我在很多论坛上看到,在变量中列出任何$之前删除&符号(&),而且我这样做,但这样做会删除我正在使用的代码的功能。我该怎么办?不推荐使用通过引用的呼叫时间?
演示here。
代码在这里:
<?php
$val = $_GET['name'];
$path = "./images/".$val."/";
$file_array = array();
readThisDir ($path, &$file_array);
echo '<div class="gallery" style="display:block;" id="'.$val.'">';
echo '<ul>';
foreach ($file_array as $file)
{
if (strstr($file, "png")||strstr($file, "jpg")||strstr($file, "bmp")||strstr($file, "gif"))
{
list($width, $height) = getimagesize($file);
$info = exif_read_data($file);
echo '<li><a href="javascript:void(0);"><img src="'.$file.'" width="'.$width.'" height="'.$height.'" alt="'.$file.'"/></a><span>'.$info['Title'].'<div class="gallerynav"><a href="javascript:void(0);" class="prevproject">«</a><a href="javascript:void(0);" class="nextproject">»</a></div></span></li>';
}
}
echo '</ul>';
echo '</div>';
function readThisDir ($path, $arr)
{
if ($handle = opendir($path))
{
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != "..")
{
if (is_dir ($path."/".$file))
{
readThisDir ($path."/".$file, &$arr);
} else {
$arr[] = $path."/".$file;
}
}
}
closedir($handle);
}
}
?>
,以飨读者:这回答我的直接问题,但@ircmaxwell提供了一个更好的选择。 – steve 2011-02-15 22:54:59