remove extension from image filename php
<p>I am loading a folder of images into a html page using the following php code.</p>

<p>The problem I am having is that the file name which is being brought through in order to be used as the image caption is showing the file extension.</p>

<p>The part of the code where the name is being pulled is the title='$img'</p>

<p>How do I get it to remove the file extension?</p>

<pre><code>&lt;?php
$string =array();
$filePath='images/schools/';  
$dir = opendir($filePath);
while ($file = readdir($dir)) { 
    if (eregi("\.png",$file) || eregi("\.jpeg",$file) || eregi("\.gif",$file) || eregi("\.jpg",$file) ) { 
        $string[] = $file;
    }
}
while (sizeof($string) != 0) {
    $img = array_pop($string);
    echo "&lt;img src='$filePath$img' title='$img' /&gt;";
}
</code></pre>

<p>?></p>
