I have a problem similar to this question, however with one more twist.
I want to explode the following string:
title:"tab system" color:="blue" price:>10
into
array("title:\"tab system\"", "color:=\"blue\"", "price:>10")
Here's what I've tried so far from the above link:
$text = "title:\"tab system\" color:=\"blue\" price:>10";
preg_match_all('/"(?:\\\\.|[^\\\\"])*"|\S+/', $text, $matches);
print_r($matches);
Which produces:
(
[0] => title:"tab
[1] => system"
[2] => color:="blue"
[3] => price:>10
)
and:
print_r(str_getcsv($text, ' '));
which produces the same thing.
These solutions don't work for me because as you can see, it's possible that the quotes may not start next to the delimiter (in this case, a space). Also, that's just one example of an input string, there could be many variations of it.