The \n
means "new line" or "line-feed", or "new line". The \r
means "Carriage Return", or "car return". When the ASCII table was standardized, the \n
received code 10 and \r
received the code 13.
The idea originally, when character encoding tables as bit sequences were designed, is that the \n
was interpreted as the command to make the cursor move down, and the \r
the command for it to move back to the beginning of the line. This distinction was important for digital typewriters that preceded computers, for digital telegraphs, for teletypes, and for the programming of the first printers that emerged. In fact, this is surprisingly older than you think, already appearing in the year 1901 along with some of the first of these character encoding tables.
Therefore, in a text for a line break to be inserted, it was necessary to use \r\n
. First the cursor should move to the beginning of the line and then down. And that was the line-breaking pattern adopted much later by Microsoft.
Multics (and later Unix) followed a different path, and decided to implement the \n
as a line-breaker, which already included a return car. After all, it doesn’t make much sense to have one thing without having the other together, and using them as one thing ensures that they will never be separated. This also has the advantage of saving space by using a single byte to encode the line break instead of two, and in those years where memory was small and low power processing, every byte saved counted for a lot.
Other companies, such as Apple and Commodore, also followed a similar path to Unix, but instead adopted the \n
for line breaks, adopted the \r
.
Other smaller companies have adopted other codes for line breaking. For example, the QNX adopted character 30 from the ASCII table. Atari adopted 155. Acorn and RISC OS adopted the \n\r
instead of \r\n
. Sinclair adopted the 118.
Sources:
\r
= Return and\n
= newline, if this developing php is usenl2br
and follow http://php.net/manual/en/function.nl2br.php ... depends on what you need.– KingRider
Thank you @Kingrider. Actually the problem isn’t even PHP, I just made a siting. Note that I didn’t add the [tag:php]. That’s because I really want to understand the meaning, when I should use, among other things.
– Wallace Maxters
Related: http://answall.com/questions/93444/qual-a-diff%C3%a7a-entre-Carriage-Return-e-line-feed
– Maniero