Page 1 of 1

converting one variable and stores into another variables

Posted: Mon Dec 05, 2005 11:03 pm
by amitshetye
hi,


i'm able to seperate the one variable and stores it into the three variable but in the following case what should i do??

i'm having one variable i.e.
$content="Jet+Airways%2CIndia%2C+Model%3A+Airbus%2C+Departure%3A+13%2F02%2Fp.m.";


In the above variable the company name is also seperated by comma and other things i.e. Model and Departure are also seperated by comma.
and my expected result is as below:

$company="Jet Airways, India";
$model="Airbus";
$departure="13.02p.m.";

so in this case what shall i do??

Posted: Mon Dec 05, 2005 11:16 pm
by Burrito
explode() it by "+"

Posted: Mon Dec 05, 2005 11:58 pm
by amitshetye
hi,

by exploding with "+" i'm not getting the values which i was accepting i.e.

$content="Jet+Airways%2C+India%2C+Model%3A+Airbus%2C+Departure%3A+13%2F02%2Fp.m.";

$company="Jet Airways, India";
$model="Airbus";
$departure="13.02p.m.";

instead i'm getting the following result

$company="Jet";
$model="Airways,";
$departure=" India";

Posted: Tue Dec 06, 2005 5:08 am
by Chris Corbyn
Upond decoding your string with urldecode() I see:

Code: Select all

Jet Airways,India, Model: Airbus, Departure: 13/02/p.m.
Now we can see a pattern too run (I'll choose regex because it seems to make sense)....

Code: Select all

$content="Jet+Airways%2C+India%2C+Model%3A+Airbus%2C+Departure%3A+13%2F02%2Fp.m.";
$decoded = urldecode($content); //Jet Airways,India, Model: Airbus, Departure: 13/02/p.m.

$parts = preg_split('@,\s+\b\w+:\s+@', $decoded);

print_r($parts);

/*
 Array
(
    [0] => Jet Airways, India
    [1] => Airbus
    [2] => 13/02/p.m.
)
 */
;)

Posted: Tue Dec 06, 2005 10:00 am
by foobar
Errr...double post?

viewtopic.php?t=41513

Plus, I answered your question there as well... :?

Posted: Tue Dec 06, 2005 10:28 am
by Chris Corbyn
Locked. Thanks.