いくつかの空白行を含むテキスト ファイルがあります。何もない行を意味し、スペースを占有しているだけです。
次のようになります。
The
quick
brown
fox jumped over
the
lazy dog
そして、私はそれを次のようにする必要があります:
The
quick
brown
fox jumped over
the
lazy dog
これらの空白行を削除し、コンテンツのある行のみを取得して新しいファイルに書き込むにはどうすればよいですか?
これが私が行う方法を知っていることです:
$file = fopen('newFile.txt', 'w');
$lines = fopen('tagged.txt');
foreach($lines as $line){
/* check contents of $line. If it is nothing or just a \n then ignore it.
else, then write it using fwrite($file, $line."\n");*/
}