我有以下脚本应该循环遍历文件的内容并删除所有空行,然后仅在没有空行的情况下重写文件。如果不用写入文件,或者用其他词语来回显文件,它就能完美地工作。但是,当我试图将其写入文件时,它只会擦除文件的所有内容。没有错误返回。我愿意开发新的脚本运行方式,因此无论如何要实现我所期待的将会很棒。提前致谢。删除文件中的所有空行
error_reporting(E_ALL);
ini_set('display_errors', true);
$filenameindex = "somefile";
$filecont = file($filenameindex);
$fileindex = fopen($filenameindex, "w") or die("can't open file");
foreach($filecont as $line)
{
if(strlen($line) > 0)
{
fwrite($fileindex,$line);
}
}
fclose($fileindex);
完美的工作!谢谢 –
这很好 - 接受答案,这对其他人很明显。 – calcinai
对不起,忘了。 –