Home > Backend Development > PHP Tutorial > Application of line breaks and (\n or \r\n and br) in php code

Application of line breaks and (\n or \r\n and br) in php code

不言
Release: 2023-03-25 12:10:02
Original
1772 people have browsed it

The browser cannot recognize \n or \r\n. These two line breaks are text line breaks and the text file is valid; if you need to output the results to the browser or print to the monitor, use br in the code; if it is just For line breaks in the source code, use \n or \r\n. Friends who are interested can learn more. It may be helpful for you to learn php

Code a:

Copy code The code is as follows:

<?php 
echo&#39;hello</br>&#39;; 
echo&#39;world!&#39;; 
?> 

output: 
helllo 
world!
Copy after login

Code b:

Copy code The code is as follows:

<?php 
echo&#39;hello\n&#39;;//unix系统使用\n;windows系统下\r\n 
echo&#39;world!&#39;; 
?> 

output: 
helloworld!
Copy after login

Analysis : The browser cannot recognize \n or \r\n. These two line breaks are text line breaks, and the text file is valid; viewing the HTML source code in the web page, you can find that code b successfully implements line breaks
Summary: If you need to output the results to the browser or print to the monitor, use
; if you just want to wrap the line in the source code, use \n or \r\n

Related recommendations:

PHP code style specification sharing

##

The above is the detailed content of Application of line breaks and (\n or \r\n and br) in php code. 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