I need to split string by spaces, but phrase in quotes should be preserved unsplitted. Example:
word1 word2 "this is a phrase" word3 word4 "this is a second phrase" word5
this should result in array after preg_split:
array(
[0] => 'word1',
[1] => 'word2',
[2] => 'this is a phrase',
[3] => 'word3',
[4] => 'word4',
[5] => 'this is a second phrase',
[6] => 'word5'
)
How should I compose my regexp to do that?
PS. There is related question, but I don't think it works in my case. Accepted answer provides regexp to find words instead of whitespaces.