Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are \r and \n meaning in PHP?

Tags:

php

What are these called? \r, \n

Is there a tutorial that explains them?

like image 546
categorizes Avatar asked Jul 18 '10 07:07

categorizes


Video Answer


3 Answers

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.)

like image 58
Jon Skeet Avatar answered Oct 18 '22 13:10

Jon Skeet


\r is the carriage return

\n is the newline

These are available in many other languages aside from PHP.

like image 29
Jacob Relkin Avatar answered Oct 18 '22 14:10

Jacob Relkin


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

like image 42
meder omuraliev Avatar answered Oct 18 '22 15:10

meder omuraliev