- print_r: documentation ( source)
- preg_match_all: documentation ( source)
<?php
$query = "-exclude -\"exclude phrase\" \"phrase 1\" keyword +k:v -k2:v2 +\"q kw\":2";
$ATOM_REGEX = '"[^"]+"|[^"\s]+';
preg_match_all("/(?P<flag>[-+])?(?P<key>$ATOM_REGEX:)?(?P<value>$ATOM_REGEX)/", $query, $match);
print_r($match);