dividing one variable and store it into another variables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
amitshetye
Forum Newbie
Posts: 12
Joined: Thu Dec 01, 2005 12:00 am

dividing one variable and store it into another variables

Post by amitshetye »

hi all,

i want to know whether it is possible to determine the particular character in the string??

i'm having one variable i.e.
$content="Air+Pacific%2C+Model%3A+Airbus%2C+Depart ure%3A+13%2F02%2Fp.m.";

i want to divide the above variable into three different variables so the result i'm expecting is :
$company="Air Pacific";
$model="Airbus";
$departure="13.02p.m.";

so is it possible in php??

anybody is having any idea??

thanx in advance

regards

amit
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post by foobar »

Next time, please put your code in [ php ] tags. Makes it a lot easier to read.

Try this:

Code: Select all

$string = urldecode('Air+Pacific%2C+Model%3A+Airbus%2C+Depart ure%3A+13%2F02%2Fp.m.');

$parts = explode(', ', $string);

foreach ($parts as $i => $part) {
  $split = explode(': ', $part);
  $parts[$i] = $split[sizeof($split)-1];
}

list($company, $model, $departure) = $parts;
Last edited by foobar on Sat Dec 03, 2005 4:52 am, edited 2 times in total.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

foobar wrote:Next time, please put your code in

Code: Select all

tags. Makes it a lot easier to read.[/quote]

also note that if you say "

Code: Select all

" without having a closing tag it will not parse the rest of message if you use the php tags properly.
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post by foobar »

shiznatix wrote:
foobar wrote:Next time, please put your code in

Code: Select all

tags. Makes it a lot easier to read.[/quote]

also note that if you say "

Code: Select all

" without having a closing tag it will not parse the rest of message if you use the php tags properly.  [/quote]

I do have a closing tag.

[edit] Oh, ok. I get it.
Post Reply