0

While reading the PHP manual on the section about, "strings" in "variable parsing" I came across a constant:

PHP_EOL

i googled it and came up with this from the manualenter link description here

"PHP_EOL (string) The correct 'End Of Line' symbol for this platform. Available since PHP 4.3.10 and PHP 5.0.2"

Doesn't really say how to use it or much of anything. What does it mean by: "The correct 'End Of Line' symbol for this platform."

when I used it in:

var_dump(PHP_EOL);

the result was:

string(1) " "

is PHP_EOL the same as \n?

Robert
  • 10,126
  • 19
  • 78
  • 130
  • 2
    An end of line character on Unix platforms is `\n`; on Windows platforms it's two characters `\r\n`; so PHP_EOL will be `n` on Linux, and `\r\n` on Windows – Mark Baker Aug 12 '14 at 23:09

1 Answers1

3

From php sources:

#ifdef PHP_WIN32
#   define PHP_DIR_SEPARATOR '\\'
#   define PHP_EOL "\r\n"
#else
#   define PHP_DIR_SEPARATOR '/'
#   define PHP_EOL "\n"
#endif

Basically, it's \r\n on win and \n otherwise (there are several other ways to represent newlines, but AFAIK, php doesn't run on those platforms).

georg
  • 211,518
  • 52
  • 313
  • 390