excluding certain files from a search within an array of names
<p>This function grabs all the jpegs from folders which match the page name and prints a background image.  On the homepage it searches all the sub directories and chooses one at random.  What i would like is to exclude (on the homepage only) certain files which match an array of names...can anyone help?</p>

<pre><code>$isHome = $this-&gt;level() == 0;

$path = 'public/images/bg/';
if (!$isHome) $path .= $this-&gt;slug;

$homepagefile = URL_PUBLIC.'public/images/bg/'.$this-&gt;slug.'/main.jpg';

$bgimagearray = array();
$iterator = new DirectoryIterator($path);
foreach ($iterator as $fileinfo) {
    if ($fileinfo-&gt;isFile() &amp;&amp; !preg_match('\.jpg$/', $fileinfo-&gt;getFilename()) &amp;&amp;  !$isHome) {
        $bgimagearray[] = "'" . $fileinfo-&gt;getFilename() . "'";
    } else if ($fileinfo-&gt;isDir() &amp;&amp; $isHome) {
        $iterator2 = new DirectoryIterator($path . $fileinfo-&gt;getFilename());
        foreach ($iterator2 as $fileinfo2) {
            if ($fileinfo2-&gt;isFile() &amp;&amp; !preg_match('\.jpg$/', $fileinfo2-&gt;getFilename())) {
                $bgimagearray[] = "'" . $fileinfo-&gt;getFilename() . '/' . $fileinfo2-&gt;getFilename() . "'";
            }
        }
    }
}

$bgimage = array_rand($bgimagearray);
</code></pre>
