php preg_match_all syntax/regex
<p>I need to grab the words out of this string and replace with AND LIKE/NOT LIKE in a sql statement, but I'm pulling my hair out trying to figure it out :-)</p>

<pre><code>$string = "hello -world !someword ! again |foo &amp;foo AND foo ORfoo";
if (preg_match_all("/AND|OR|\||&amp;|!|\-(\w+)/", "$string", $matches)) {
        foreach ($matches as $match) {
                foreach ($match as $m) {
                        // 1. figure out what the delimiter was (!, |, &amp;, -, AND, OR
                        // 2. create a sql statement from it using the word following the delimiter
                        // Example:
                        if ($m = "!") {
                                $where .= " AND msg NOT like '%".$m."%'";
                        }
                        if ($m = "AND") {
                                $where .= " AND msg like '%".$m."%'";
                        }
                        if ($m = "OR") {
                                $where .= " OR msg like '%".$m."%'";
                        }
                }
        }
}
echo $where;
</code></pre>
