php pathinfo() expects parameter 1 to be string, array given in [duplicate]

末鹿安然 提交于 2019-12-20 07:56:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!