converting one variable and stores 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

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

converting one variable and stores into another variables

Post 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??
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

explode() it by "+"
amitshetye
Forum Newbie
Posts: 12
Joined: Thu Dec 01, 2005 12:00 am

Post 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";
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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.
)
 */
;)
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post by foobar »

Errr...double post?

viewtopic.php?t=41513

Plus, I answered your question there as well... :?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Locked. Thanks.
Locked