我试图在这里基于代码获得基于HTML的递归目录列表:
http://webdevel.blogspot.in/2008/06/recursive-directory-listing-php.html
代码运行正常,但它会引发一些错误:
严格标准:在第34行的C:\ xampp\htdocs\directory5.php中只能通过引用传递变量
严格标准:只应在第32行的C:\ xampp\htdocs\directory5.php中通过引用传递变量
严格标准:在第34行的C:\ xampp\htdocs\directory5.php中只能通过引用传递变量
以下是代码的摘录:
else
{
// the extension is after the last "."
$extension = strtolower(array_pop(explode(".", $value))); //Line 32
// the file name is before the last "."
$fileName = array_shift(explode(".", $value)); //Line 34
// continue to next item if not one of the desired file types
if(!in_array("*", $fileTypes) && !in_array($extension, $fileTypes)) continue;
// add the list item
$results[] = "<li class=\"file $extension\"><a href=\"".str_replace("\\", "/", $directory)."/$value\">".$displayName($fileName, $extension)."</a></li>\n";
}
Run Code Online (Sandbox Code Playgroud)
hal*_*ush 56
这应该没问题
$value = explode(".", $value);
$extension = strtolower(array_pop($value)); //Line 32
// the file name is before the last "."
$fileName = array_shift($value); //Line 34
Run Code Online (Sandbox Code Playgroud)
Shi*_*dim 24
array_shift
唯一的参数是通过引用传递的数组.返回值explode(".", $value)
没有任何参考.因此错误.
您应该首先将返回值存储到变量中.
$arr = explode(".", $value);
$extension = strtolower(array_pop($arr));
$fileName = array_shift($arr);
Run Code Online (Sandbox Code Playgroud)
来自PHP.net
以下内容可以通过引用传递:
- Variables, i.e. foo($a)
- New statements, i.e. foo(new foobar())
- [References returned from functions][2]
Run Code Online (Sandbox Code Playgroud)
不应该通过引用传递其他表达式,因为结果是未定义的.例如,以下通过引用传递的示例无效: