Description of the PHP_EOL DIRECTORY_SEPARATOR constant
PHP_EOL is a constant of linefeed defined in the php system source code.
Why is there such a constant?
Because in different systems, line breaks are different. For example:
\ N for unix
Windows \ r \ n
Mac \ r
Php defines PHP_EOL. This constant will change based on the platform to improve the source code portability.
<? Phpecho PHP_EOL; // the windows platform is equivalent to echo "\ r \ n"; // the unix \ linux platform is equivalent to echo "\ n"; // The mac platform is equivalent to echo "\ r ";
Similar to common
DIRECTORY_SEPARATOR
Php's built-in constant DIRECTORY_SEPARATOR is a command for displaying system delimiters and can be directly used without any definition or inclusion.
As we all know, in windows, the path separator is \ (of course/can run normally On some systems). in linux, the path separator is/, which leads to a problem, for example, if the development machine is windows and there is an Image Upload program, the directory for storing the specified upload files on the debugging machine is:
define('ROOT', dirname(__FILE__)."\upload");
Local debugging is normal, but an error occurs after being uploaded to the linux server. Therefore, the code above is written as follows:
Define ('root', dirname (_ FILE _). DIRECTORY_SEPARATOR. "upload ");
Tip: You can use the get_defined_constants () function to obtain all PHP constants. For example:
<? Phpprint_r (get_defined_constants (); // get_defined_constants () returns all constant Arrays
Articles you may be interested in
- Php built-in variable DIRECTORY_SEPARATOR Parsing
- Php $ GLOBALS super global variable analysis
- Summary of system constants in the Action controller of thinkphp
- Summary of common system variables in Thinkphp templates
- Use php functions in the smarty template and how to use multiple functions for a variable in the smarty Template
- Five major php operating modes: CGI, FAST-CGI, CLI, ISAPI, and APACHE
- Common PHP variable judgment Functions
- Constant analysis in PHP