问题
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