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?
If you need to insert a Carriage Return in a string in PHP: Carriage return is: "\r" But carriage return (CR) is different from "new line" (NL) New Line (NL) is "\n" What in HTML is called "line break" is the sum of a CR and a NL.
The CRLF abbreviation refers to Carriage Return and Line Feed. CR and LF are special characters (ASCII 13 and 10 respectively, also referred to as \r\n) that are used to signify the End of Line (EOL).
Description. The term CRLF refers to Carriage Return (ASCII 13, \r ) Line Feed (ASCII 10, \n ). They're used to note the termination of a line, however, dealt with differently in today's popular Operating Systems.
It's as simple as doing:
echo "\r\n";
(note the double quotes)
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.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With