a string on spaces but not when the space is inside parentheses.
Str = 'abc "de fg" hij "kl m n" op'
This string needs to be split into array like:
[0] => abc
[1] => de fg
[2] => hij
[3] => kl m n
[4] => op
I know I need to use preg_split for it, but I can't think of any regex solution for this.
Any ideas?
You can use explode(), just say $str = "ABC defg hij klmn op"; print_r(explode(" ", $str));
Try this: Replace those space with - in your data. Then $str = 'ABC "de-fg" hij kl-mn op'; $arrayConv = explode(' ', $str); $removeDash = str_replace('-', ' ', $str); Print_r($removeDash);
Обсуждают сегодня