What do \r and \n mean in PHP (and other languages)?
Solution 1:
They're "carriage return" and "line feed" respectively. Typically on Windows, you need both together to represent a line terminator: "\r\n" whereas on most (all?) Unix systems, "\n" is enough.
See the Wikipedia Newline entry for more details about the vagaries of different systems.
See the PHP manual for more details about escape sequences in general, and the other ones available in PHP.
Many other languages (e.g. C, C++, C#, Java, Perl, Python, Ruby) share the same escape sequences for carriage return and line feed - but they are all specified for the individual language. (In other words, it is language specific, but the answer would be the same for many languages.)
Solution 2:
\r
is the carriage return
\n
is the newline
These are available in many other languages aside from PHP.
Solution 3:
They're escape sequences. \n
is a newline and \r
is a carriage return.
In Windows most text editors have a newline as \r\n and on unix it's \n
Solution 4:
Not an answer to your question, but relevant nonetheless: I'd recommend using the PHP_EOL constant whenever you want to insert a new line. The PHP_EOL constant contains the correct new line character(s) for the platform on which the script is being run (\n on Unix, \r\n on Windows).
Solution 5:
\r
is a Carriage Return
\n
is a Line Feed (or new line).
On Windows systems these together make a newline (i.e. every time you press the enter button your fix will get a \r\n
).
In PHP if you open a Windows style text file you will get \r\n
at the end of paragraphs / lines were you've hit enter. If it was a Unix style text file you'd only get a \n
.