PHP_EOL is a newline character constant defined in the PHP system source code.
Why is there such a constant?
Because the newline characters are different in different systems. For example:
For unix series n
For windows series rn
r for mac
So PHP_EOL is defined in PHP. This constant will change according to the platform to improve the source code level portability of the code.
<?php echo PHP_EOL; //windows平台相当于 echo "\r\n"; //unix\linux平台相当于 echo "\n"; //mac平台相当于 echo "\r";
Similar and commonly used ones are
DIRECTORY_SEPARATOR
PHP’s built-in constant DIRECTORY_SEPARATOR is a command that displays the system separator and can be used directly without any definition or inclusion.
As we all know, the path separator under Windows is (of course / can also run normally on some systems), and the path separator on Linux is /, which leads to a problem. For example, the development machine is Windows, there is an image upload program, the designated upload file saving directory on the debugging machine is:
define('ROOT', dirname(__FILE__)."\upload");
It is normal to debug locally, but an error will occur after uploading to the Linux server. Therefore, the strict writing method of the above code is:
define('ROOT', dirname(__FILE__).DIRECTORY_SEPARATOR."upload");
Tip: You can use the function get_defined_constants() to get all PHP constants, for example:
<?php print_r(get_defined_constants());//get_defined_constants()返回所有常量数组