PHP - Whats the difference between \n and \r

December 2016



Issue


What is the difference between \n (line feed) and \r (carriage return)?
They seems to be exactly the same ... Are there cases where the use of one is better than the other?

Solution


The '\n' is the LF (Line Feed) and '\r' is the CR (carriage return). Under Windows both are required to make a line termination/line break code (LF + CR).
  • Under Unix and Linux system a simple LF is enough to indicate a line break.



Thanks to crabs for this tip.

Related :

This document entitled « PHP - Whats the difference between \n and \r » from CCM (ccm.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.