Home >Backend Development >PHP Problem >What are the line breaks in php?
When writing PHP script code, we often see the two characters \n and
. They both have the function of breaking lines, so what exactly do they mean? What's the difference?
1, \n or \r\n, causes the source code to wrap, but the content displayed by the browser does not;
2,
causes the browser to display The content wraps, but the source code does not.
Example:
PHP code 1:
<?php echo 0; echo "\n"; echo 1; ?>
Browser display:
View source code:
PHP code 2:
<?php echo 0; echo "<br />"; echo 1; ?>
Browser display:
##View source code : 3. PHP_EOLIn PHP, PHP_EOL is equivalent to a very compatible newline character. This variable will change according to the platform. In Windows It will be /r/n under Linux, /n under Linux, and /r under Mac. It is adaptable to multiple platforms.<?php echo PHP_EOL; //windows平台相当于 echo "\r\n"; //unix\linux平台相当于 echo "\n"; //mac平台相当于 echo "\r";Note: There is a pit here, it is used for text line wrapping, not html line wrapping. Often used for log file recording. Therefore, line breaks will not be displayed when opening the html file. For more PHP related knowledge, please visit
php中文网!
The above is the detailed content of What are the line breaks in php?. For more information, please follow other related articles on the PHP Chinese website!