问题描述
我有一个脚本,该脚本有错误- pathinfo()期望参数1为字符串,在第4行的C:\xampp\htdocs\sitename\index.php中给出数组,如何修复脚本是
I have a script that has the error-- pathinfo() expects parameter 1 to be string, array given in C:\xampp\htdocs\sitename\index.php on line 4--, how to fix a script is
<?php
$dir = 'dir1/dir2/dir3/dir4/';
$phpfiles = glob($dir ."*.php");
line error ---> $pathinfo= pathinfo($phpfiles, PATHINFO_FILENAME );
foreach ($phpfiles as $phpfile){
echo '<li><a href="'.$phpfile.'">'.$phpfile.'</a></li>';
}
?>
推荐答案
pathinfo返回一个关联数组,它不允许数组作为参数。请参阅文档:
pathinfo returns an associative array, it does not allow an array as a parameter. See the docs: http://www.php.net/manual/en/function.pathinfo.php
您的glob将返回包含文件的数组。
Your glob will return an array with files.
路径:要解析的路径。
选项:如果存在,则指定要返回的特定元素;
path: The path to be parsed.options: If present, specifies a specific element to be returned; one of PATHINFO_DIRNAME, PATHINFO_BASENAME, PATHINFO_EXTENSION or PATHINFO_FILENAME.
如果未指定选项,则返回所有可用元素。
If options is not specified, returns all available elements.
这篇关于php pathinfo()期望参数1为字符串,数组在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!