Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When do I use the PHP constant "PHP_EOL"?

Tags:

php

eol

When is it a good idea to use PHP_EOL?

I sometimes see this in code samples of PHP. Does this handle DOS/Mac/Unix endline issues?

like image 211
Christian Oudard Avatar asked Sep 24 '08 17:09

Christian Oudard


People also ask

Whats PHP_EOL?

What is PHP_EOL? Introduced in version 5.0. 2 of php, PHP_EOL is a string constant that represents the correct end of line symbol for the platform that you are running php on. So on Windows this should be set to "\r\n" (carriage return and line feed) and on a *nix system it should be set to "\n" (only line feed).

How do you call a constant in PHP?

A constant is an identifier (name) for a simple value. The value cannot be changed during the script. A valid constant name starts with a letter or underscore (no $ sign before the constant name). Note: Unlike variables, constants are automatically global across the entire script.


1 Answers

Yes, PHP_EOL is ostensibly used to find the newline character in a cross-platform-compatible way, so it handles DOS/Unix issues.

Note that PHP_EOL represents the endline character for the current system. For instance, it will not find a Windows endline when executed on a unix-like system.

like image 156
Adam Bellaire Avatar answered Oct 07 '22 00:10

Adam Bellaire