我是PHP新手,現在仍在學習。這次我想打印一些文本並保存在一個文件中。但我想要自動更改文件名稱。如何在使用PHP保存文件時迭代文件名?
例如file1.txt,file2.txt,file3.txt等。 這裏是我到目前爲止的代碼:
$read = file("example.txt",FILE_IGNORE_NEW_LINES);
$newFile = "file_1.txt";
$of = fopen($newFile,'w');
foreach($read as $k => $file){
$line = explode(" ",$file);
$line2 = array_slice($line,0,3);
foreach($line2 as $value){
echo $value." ";
fwrite($of,$value." ");
}
echo "<br>";
fwrite($of,"\n");
}
fclose($of);
先寫入僞代碼(即人類可讀的描述)。在轉換爲PHP時將其保留爲註釋。 –