我有以下测试脚本:
<?php
$myFile = "testFile.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "Floppy Jalopy\n";
fwrite($fh, $stringData);
$stringData = "Pointy Pinto\n";
fwrite($fh, $stringData);
fclose($fh);
?>
当使用记事本打开时,运行后,数据以单行形式返回,没有换行,如下所示:
Floppy Jalopy(疯狂盒子)Pointy Pinto(疯狂盒子)
我无法找到适合“疯狂盒子”的字符,但它是一个非常疯狂的盒子。这是为什么呢?
PHP_EOL
。但根据我的经验,大多数情况下,你创建的文件是用于下载、发送电子邮件或以后解析,这些情况下你需要具有特定换行符的文件,而不是脚本运行平台上的默认换行符。 - AndreKR