Hi,
Is there a split function in PHP? Like the one in CGI.
Eg. in CGI :
$data = 'Lyon-Male';
($name,$value) = split(/-/, $data);
So $name gets Lyon and $value gets Male..
How do I achieve this in PHP?
Thanks to all.
| SitePoint Sponsor |





Hi,
Is there a split function in PHP? Like the one in CGI.
Eg. in CGI :
$data = 'Lyon-Male';
($name,$value) = split(/-/, $data);
So $name gets Lyon and $value gets Male..
How do I achieve this in PHP?
Thanks to all.
"Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
-- Albert Einstein
I don't know if you can split into variables in PHP, but you can do it with another step:
http://www.php.net/manual/function.explode.php
$data = 'Lyon-Male';
$array = explode("-", $data");
$name = $array[0];
$value = $array[1];





wow..
you're amazing..thanks a million!
"Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
-- Albert Einstein

Hopefully the following code will help you a little:
useful url's:Code:example 1: $v = "rob-pengelly"; list($first,$last) = explode('-',$v); echo "$first $last"; output: rob pengelly example 2: $v = "rob.pengelly"; list($first,$last) = split('\.',$v); echo "$first $last"; output: rob pengelly example 3: $v = "test0-test1.test2,test3"; $output = split("[-.,]",$v); foreach($output as $value) { print $value."\n"; } output: test0 test1 test2 test3
http://www.php.net/split
http://www.php.net/explode
Bookmarks