考虑到我从一个文件夹(g-images /)创建一个图库并使用文件名作为标题的工作代码,我该如何从这些标题中排除除* .jpg之外的其他文件扩展名(即*。 png,* .gif)?如何从文件夹中使用文件名作为PHP库的标题时排除文件扩展名?
此刻被删除的唯一扩展名是* .jpg。如果它是任何其他扩展它保存为标题对图像的一部分...
HELP,总新手在这里:-)
<?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->read()) {
if (eregi("gif", $file) || eregi("jpg", $file) || eregi("png", $file)){
$imglist[] = $file;
}
}
closedir($imgs->handle);
//display image
foreach($imglist as $image) {
echo '<li><a href="'.$img_folder.$image.'" target="zoomed"><img src="timthumb.php?src='.$img_folder.$image.'&a=r&h=260" />';
echo '<p>'.str_replace('.jpg', ' ', str_replace('name', 'Name', $image)).'</p></a></li>';
}
?>
感谢大家的帮助!我真的很感激,欢呼! :-) – kcullen