note 71983 deleted from function.preg-match-all by colder
| From: | colder@php.net | Date: | Sun, 18 Mar 2007 16:29:58 +0000 |
| Subject: | note 71983 deleted from function.preg-match-all by colder | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-124574@lists.php.net to get a copy of this message | ||
Note Submitter: madmax
----
This function is useful to parse search queries with escaped quotes
<?php
print_r(parse_words('some text "quoted text" other text'));
function parse_words($text, $minlength = 3)
{
$result = Array();
if(@preg_match_all('/"(?P<string>[^"\\\\]{' . $minlength .
',}(?:\\\\.[^"\\\\]*)*)"|(?P<words>[^ "]{' . $minlength .
',})/', $text, $regs))
{
if(($result = @array_unique(@array_filter($regs['words']) +
@array_filter($regs['string']))) !== NULL)
{
@ksort($result, SORT_NUMERIC);
};
};
return($result);
};
?>
result:
Array
(
[0] => some
[1] => text
[2] => quoted text
[3] => other
)