Home  >  Article  >  Backend Development  >  What are the line breaks in php?

What are the line breaks in php?

青灯夜游
青灯夜游Original
2019-10-17 15:22:369555browse

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:

What are the line breaks in php?

View source code:

What are the line breaks in php?

PHP code 2:

<?php
echo 0;
echo "<br />";
echo 1;
?>

Browser display:

What are the line breaks in php?

##View source code :

What are the line breaks in php?

3. PHP_EOL

In 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!

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