drnpwmq4536 2017-07-04 23:17
浏览 17
已采纳

php:如何修复''Array()''? 我试图从文件夹中的每个单独的文件中获取内容

    <?php

        function cmp($a, $b) {
            if (filemtime($a) == filemtime($b))
                return 0;

            return (filemtime($a) < filemtime($b)) ? -1 : 1;
        }


        $files = glob("/Users/xx/Desktop/2011/cdr/*.cdr");
        usort($files, "cmp");

        foreach($files as $file)

            //echo $file . "<br />";
            // echo "$file was last modified: " . date ("d-m-Y H:i:s.", filemtime($file))."
";


    $file1 = file_get_contents($file, FILE_USE_INCLUDE_PATH);


    $arr1 = explode("
", $file1);


    $data1 = array();



     foreach ($arr1 as $key => $value) {
 $split = explode(";", $value);

 $keys = md5(uniqid(rand(), true));
}
 print_r($data1);
?>

I am trying to get contents from each file but it keep getting below

Array ( )

Question is how can i fix the error when am trying to get contents from each individual file in a folder? Should i make a loop to read from each file separately ?

展开全部

  • 写回答

1条回答 默认 最新

  • dongzha0149 2017-07-04 23:27
    关注
    $files = glob("/Users/xx/Desktop/2011/cdr/*.cdr");
    

    This call to glob() will return an array of absolute paths like:

    "/Users/xx/Desktop/2011/cdr/example.cdr"
    

    The path is part of the returned value! (This is unlike some other functions like readdir().) You don't need to append the path again when you call file_get_contents().

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?