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

What are the line breaks in php?

青灯夜游
Release: 2023-02-27 07:54:01
Original
9638 people have browsed it

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;
?>
Copy after login

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;
?>
Copy after login

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";
Copy after login
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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template