且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP输出文本文件中的新行

更新时间:2023-12-04 13:31:40

其他答案指出,您需要在每个字段后添加行尾字符.

As other answers state, you need to add in an end of line character after each field.

但是,不同的操作系统使用不同的行尾,因此,例如,"\ n"可能不会在Windows上显示为新行.正如Mahdi所说,您可以使用Windows样式的"\ r \ n"行尾,也可以使用 PHP_EOL 常量,以便输出适合服务器的行尾,在这种情况下,您的代码应类似于

Different OS's use different line endings, though, and so a "\n" may not display as a new line on Windows, for example. As Mahdi said, you can use Windows style "\r\n" line endings, or you can use the PHP_EOL constant so that line endings appropriate to the server will be output, in which case your code would look like

$data = $_POST['name'] . PHP_EOL;
$data .= $_POST['email'] . PHP_EOL;
$data .= $_POST['message'] . PHP_EOL;