Use explode
with a limit:
$array = explode(' ', $string, 2);
Just a side note: the 3rd argument of preg_split
is the same as the one for explode
, so you could write your code like this as well:
$array = preg_split('#\s+#', $string, 2);
References:
PHP: explode
PHP: preg_split