我很新的PHP所以我还在学习非常基础,但是我想创建一个图片库。按字母顺序排序由opendir()
经过无数谷歌搜索后,我发现了一个PHP脚本,做什么,我希望它做的,看代码,并稍微操纵它,它与我的网站可以正常使用后,除了图像不是按字母顺序排列的。
这是代码
$max_width = 100;
$max_height = 100;
$imagedir = 'gifs/animals/'; //Remember trailing slash
function getPictureType($ext) {
if (preg_match('/jpg|jpeg/i', $ext)) {
return 'jpg';
} else if (preg_match('/png/i', $ext)) {
return 'png';
} else if (preg_match('/gif/i', $ext)) {
return 'gif';
} else {
return '';
}
}
function getPictures() {
global $max_width, $max_height, $imagedir;
if ($handle = opendir($imagedir)) {
$lightbox = rand();
echo '<ul id="pictures">';
while (($file = readdir($handle)) !== false) {
if (!is_dir($file)) {
$split = explode($imagedir, $file);
$ext = $split[count($split) - 1];
if (($type = getPictureType($ext)) == '') {
continue;
}
$name = substr($file, 0, -4);
$title = str_replace("_"," ",$name);
echo '<li><a href="'.$name.'">';
echo '<img src="thumbs/'.$file.'" class="pictures" alt="'.$file.'" />';
echo '</a>';
echo ''.$title.'';
echo '</li>';
}
}
echo '</ul>';
}
}
我使用这在按字母顺序排序它们的运作SCANDIR()函数,但是我留下了的阵列。然后,我使用implode函数将数组连接在一起,然而之后我仍然不知所措。
任何帮助将不胜感激!
干杯。
谢谢,这工作。 – Polar 2012-02-14 09:27:43