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??
converting one variable and stores into another variables
Moderator: General Moderators
-
amitshetye
- Forum Newbie
- Posts: 12
- Joined: Thu Dec 01, 2005 12:00 am
-
amitshetye
- Forum Newbie
- Posts: 12
- Joined: Thu Dec 01, 2005 12:00 am
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";
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";
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Upond decoding your string with urldecode() I see:
Now we can see a pattern too run (I'll choose regex because it seems to make sense)....

Code: Select all
Jet Airways,India, Model: Airbus, Departure: 13/02/p.m.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.
)
*/- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia