more efficient code
Posted: Fri Jun 22, 2007 11:07 am
The below code work perfectly. It looks in the appropriate directory, displays all the images with a "t" (thumbnails) and that links to the full size image. The thing is, I feel that the ereg_replace(), which takes away the "t", is a bit of a hack in this situation. Anyone have suggestion on how to clean this up? Thanks in advance.
Code: Select all
/*Check for Images then display the thumbnail */
$path="images/work/".$row['project_id'].'/';
$dir=opendir($path);
while($name=readdir($dir)){
if (preg_match("/t+([0-9]+)\.jpg$/",$name)){
$nameb=ereg_replace('t','', $name); //<-- not happy with this
echo '<a href="'.BASE_URL.$path.$nameb.'" rel="lightbox">';
echo '<img src="'.BASE_URL.$path.$name.'" alt="'.$row['project_name'].'" width="120" /> ';
echo '</a>';
}
}