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:

php: explode

php: preg_split


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -