If i have
$cmdline = "arg0 'arg1a arg1b' arg2";
how can I parse it to
$args[0] = "arg0"; $args[1] = "arg1a arg1b"; $args[2] = "arg2";
instead of
$args[0] = "arg0"; $args[1] = "'arg1a"; $args[2] = "arg1b'"; $args[3] = "arg2";
(as explode does)?
preg_match_all("/['\s]+|'.*?'/", $cmdline, $matches); $args=$matches[0];
Match a consecutive sequences of non-whitespace chars that do not contain an apostrophe, or an apostrophe followed by some chars followed by another apostrophe.