php - How can I explode a string into an array by space, but preserve quoted words? -
given string abc "def ghi"
, how can return array:
[0] => abc [1] => def ghi
other examples:
abc "def ghi" => ['abc','def ghi'] abc def => ['abc','def']
$str = 'abc "def ghi"'; $arr = str_getcsv($str, ' ', '"'); print_r($arr);
returns:
array ( [0] => abc [1] => def ghi )
Comments
Post a Comment