php - split at the first space in a string -
i have string this:
red yellow blue
and want array :
array ( [0] => red [1] => yellow blue )
how split @ first space in string ? code doesn't work
<?php $str = "red yellow blue"; $preg = preg_split("/^\s+/", $str); print_r($preg); ?>
please me.
use explode
limit:
$array = explode(' ', $string, 2);
just side note: 3rd argument of preg_split
same 1 explode
, write code well:
$array = preg_split('#\s+#', $string, 2);
references: