小编use*_*164的帖子

读取特定文件夹中的所有txt文件,并将所有内容写入一个txt文件中

我尝试*.txt从文件夹中读取所有文件,并将每个文件中的所有内容写入另一个txt文件.但不知何故,它只在txt文件中写入一行.

我试过,fwrite()file_put_contents()没有奏效.

这是我的代码:

<?php

    $dh = opendir('/Applications/XAMPP/xamppfiles/htdocs/test/');

    while($file = readdir($dh)) {
        $contents = file_get_contents('/Applications/XAMPP/xamppfiles/htdocs/test/' . $file);
        $dc = array($contents);   
    }

    file_put_contents('content.txt', $dc);

?>
Run Code Online (Sandbox Code Playgroud)

php file

1
推荐指数
1
解决办法
7088
查看次数

标签 统计

file ×1

php ×1