![](/img/trans.png)
[英]How can i save all the variable results from a echo into a txt file using php?
[英]How to Save Results from Foreach into Txt File
我想將特定文件夾中的所有文件寫入 .txt 文件。 output 工作得很好,但我只將一個文件保存到我的 txt 文件中。 任何想法? 謝謝!
$fileList = glob('C:\users\John\Documents\*pdf');
foreach($fileList as $filename){
if(is_file($filename)){
echo $filename, '<br>';
$save_files = fopen("list.txt", "wb");
fwrite($save_files,$filename);
fclose($save_files);
}
}
這是一種方法...
foreach($fileList as $filename){
if(is_file($filename)){
echo $filename, '<br>';
$list[] = $filename;
}
}
$capture = implode("\r\n",$list);
file_put_contents("list.txt",$capture);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.