Given the string abc "def ghi"
, how can I return the array:
[0] => abc
[1] => def ghi
Other examples:
abc "def ghi" => ['abc','def ghi']
abc def => ['abc','def']
Given the string abc "def ghi"
, how can I return the 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
)
You can use:
$s = 'abc "def ghi"';
preg_match_all('/(?>"[^"]*"|\S+)/', $s, $m);
print_r($m[0]);
Array
(
[0] => abc
[1] => "def ghi"
)