Searching for a string within a string with php?
<p>I am in a bit of a dilemma and can't seem to work out why the following code is not functioning as it should.</p>

<pre><code>function find($haystack, $needles) {
    $needle = array_map('trim', explode(",", $needles));
    foreach ($needle as $key =&gt; $value) {
        if (strpos($haystack, $value) !== false) {
            return true;
        }
    }
    return false;
}
</code></pre>

<p>I am using the following code as a method to determine what elements should be shown on certain pages or to add classes to certain elements. For example I would use</p>

<pre><code>&lt;?php if (find($section, "home")) { ?&gt; class="current"&lt;?php } ?&gt;
</code></pre>

<p>to add the class current if <code>$section = "home"</code>. I can also use this function to show certain elements on multiple pages for example</p>

<pre><code>&lt;?php if (find($section, "about, media")) { ?&gt;
</code></pre>

<p>and the same if I want to show elements on all pages but not on a selection</p>

<pre><code>&lt;?php if (!find($section, "contact")) { ?&gt;
</code></pre>

<p>and lastly it can be used on multiple variables for example.</p>

<pre><code>&lt;?php if (find($page, "news") || find($section, "news")) { ?&gt;
</code></pre>

<p>It's when I use the function to try to create a more complex if statement to remove elements from a selection of pages that it seems to fail, in this example the variables and if statement look like this if you on the news section page or the news post page:</p>

<pre><code>&lt;?php if (!find($page, "news") || !find($section, "news")) { ?&gt;
</code></pre>

<p><code>$page = "news"</code> and <code>$section = "media news section"</code><br>
<code>$page = "post"</code> and <code>$section = "media news post dynamic"</code></p>

<p>I can't work out why it's not returning false for these specific statements. Any help would be grateful or a better direction/method is welcome. Many thanks</p>
