【发布时间】:2010-10-27 11:09:35
【问题描述】:
php noob here - 我拼凑了这个脚本以显示来自 opendir 文件夹的图像列表,但我无法确定如何(或在哪里)按字母顺序对数组进行排序
<?php
// opens images folder
if ($handle = opendir('Images')) {
while (false !== ($file = readdir($handle))) {
// strips files extensions
$crap = array(".jpg", ".jpeg", ".JPG", ".JPEG", ".png", ".PNG", ".gif", ".GIF", ".bmp", ".BMP", "_", "-");
$newstring = str_replace($crap, " ", $file );
//asort($file, SORT_NUMERIC); - doesnt work :(
// hides folders, writes out ul of images and thumbnails from two folders
if ($file != "." && $file != ".." && $file != "index.php" && $file != "Thumbnails") {
echo "<li><a href=\"Images/$file\" class=\"thickbox\" rel=\"gallery\" title=\"$newstring\"><img src=\"Images/Thumbnails/$file\" alt=\"$newstring\" width=\"300\" </a></li>\n";}
}
closedir($handle);
}
?>
任何建议或指示将不胜感激!
【问题讨论】: