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

不言
不言Original
2018-05-04 16:20:581774browse

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!

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!

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 0b9f73f8e206867bd1f5dc5957dbcb38; 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!

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