我尝试*.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)