Page 1 of 1

dividing one variable and store it into another variables

Posted: Sat Dec 03, 2005 3:15 am
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

Posted: Sat Dec 03, 2005 4:48 am
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;

Posted: Sat Dec 03, 2005 4:50 am
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.

Posted: Sat Dec 03, 2005 4:51 am
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.