问题
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>';
}
?>
回答1:
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
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.
来源:https://stackoverflow.com/questions/23808894/php-pathinfo-expects-parameter-1-to-be-string-array-given-in