使php中的新行写入文件

Gho*_*tff 4 php fwrite

我试过这个,但不会工作

<?php
$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
$txt = "Mickey Mouse\n";
fwrite($myfile, $txt);
$txt = "Minnie Mouse\n";
fwrite($myfile, $txt);
fclose($myfile);
?> 
Run Code Online (Sandbox Code Playgroud)

这是它在我的 newfile.txt 中的显示方式:

Mickey MouseMinnie Mouse`
Run Code Online (Sandbox Code Playgroud)

但我想要这样:

Mickey Mouse
Minnie Mouse
Run Code Online (Sandbox Code Playgroud)

Mar*_*mel 6

最好使用 PHP_EOL。它是跨平台的,会自动为 PHP 运行的平台选择正确的换行符。

$txt = "Goofy".PHP_EOL;
Run Code Online (Sandbox Code Playgroud)