PHP search word in string
<p>I'm trying to scan a piece of text for the occurrence of certain words. If the string contains any of these words, the function should return TRUE. <code>in_array</code> can accept two arrays but it seems that all elements of the needle need to be found in the haystack for the return to be TRUE.</p>

<p>From the user manual - returns TRUE</p>

<pre><code>$a = array(array('p', 'h'), array('p', 'r'), 'o');

if (in_array(array('p', 'h'), $a)) {
   return TRUE
}
</code></pre>

<p>But this doesn't return TRUE.</p>

<pre><code>$a = array(array('p', 'h'), array('p', 'r'), 'o');

if (in_array(array('p', 'x'), $a)) {
    return TRUE
}
</code></pre>

<p>I can write the function with an if/else for every word I want to find but that seems a bit cumbersome. Is there a better way, perhaps with regex?</p>

<p>Background: the text I'm searching in is about 200 words max, so I explode on <code>" "</code> to make an array in which I then search.</p>
