phpstring

Is a new line = \n OR \r\n?


I've seen many developers use different methods to split a string by new lines, but i'm confused which is the correct: \r\n OR \n only?


Solution

  • \n is used for Unix systems (including Linux, and OSX).

    \r\n is mainly used on Windows.

    \r is used on really old Macs.

    PHP_EOL constant is used instead of these characters for portability between platforms.