title: how to exclude file extensions when using file names as captions for PHP gallery from folder?
body: <p>Considering my working code for creating a gallery from a folder (g-images/) and using the file names for captions, <strong>how do I go about to exclude from such captions other file extensions other than *.jpg (i.e. *.png, *.gif)?</strong></p>
  
  <p>at the moment the only extension that gets removed is *.jpg. if it's any other extension it's kept as part of the caption for the image...</p>
  
  <p>HELP, total newbie here :-)</p>
  
  <pre><code>&lt;?php
     $imglist = array();
     $img_folder = "g-images/";
  
     //use the directory class
     $imgs = dir($img_folder);
  
     //read all files from the  directory, checks if are images and adds them to a list 
     while ($file = $imgs-&gt;read()) {
     if (eregi("gif", $file) || eregi("jpg", $file) || eregi("png", $file)){
     $imglist[] = $file;
     } 
   }
   closedir($imgs-&gt;handle);
  
   //display image
   foreach($imglist as $image) {
   echo '&lt;li&gt;&lt;a href="'.$img_folder.$image.'" target="zoomed"&gt;&lt;img src="timthumb.php?src='.$img_folder.$image.'&amp;a=r&amp;h=260" /&gt;';
   echo '&lt;p&gt;'.str_replace('.jpg', ' ', str_replace('name', 'Name', $image)).'&lt;/p&gt;&lt;/a&gt;&lt;/li&gt;';
   }
  ?&gt;
  </code></pre>