PHP echo the equivalent of CR LF of Notepad

一世执手 提交于 2021-02-08 12:20:49

问题


I need to export some data using PHP and for each line I'm adding a \r\n. When I open the exported data file that I downloaded, I see that the \r\n is interpreted as [LF] in Notepad.

But the application in which I open the file doesn't read the [LF] as a new line.

Now if I do a [CR][LF] in Notepad, the application can read the [CR][LF] as a new line.

How can I echo the equivalent of [CR][LF] with PHP?


回答1:


It's as simple as doing:

echo "\r\n";

(note the double quotes)




回答2:


Do echo PHP_EOL;

That way it'll always display the correct linefeed/carriage return combination that's valid for the system you're on, since not all OSes use the same newline convention. (More information: PHP global constants.)




回答3:


Problem solved: the string was passed in the POST parameter. Removing the \r.

You just have to do a str_replace("\n", "\r\n", $...);.



来源:https://stackoverflow.com/questions/11222604/php-echo-the-equivalent-of-cr-lf-of-notepad

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!