Home >Backend Development >PHP Tutorial >Description of PHP_EOL DIRECTORY_SEPARATOR constant_PHP tutorial

Description of PHP_EOL DIRECTORY_SEPARATOR constant_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 09:56:36897browse

PHP_EOL Description of the DIRECTORY_SEPARATOR constant

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()返回所有常量数组

Articles you may be interested in

  • Analysis of php’s built-in variable DIRECTORY_SEPARATOR
  • php $GLOBALS super global variable analysis
  • thinkphp’s Action control Summary of system constants in the processor
  • Summary of commonly used system variables in Thinkphp templates
  • Using php functions in smarty templates and how to use multiple functions for one variable in smarty templates
  • A brief discussion of PHP’s five major operating modes: CGI, FAST-CGI, CLI, ISAPI, and APACHE modes
  • Commonly used functions for judging variables in PHP
  • Constant analysis in PHP

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/987399.htmlTechArticlePHP_EOL Description of the DIRECTORY_SEPARATOR constant PHP_EOL is a newline constant defined in the PHP system source code. Why is there such a constant? Because in different systems, line breaks...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn