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.
Printable View
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.
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!
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