Home >Backend Development >PHP Tutorial >Application of line breaks and (\n or \r\n and br) in php code
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'hello</br>'; echo'world!'; ?> output: helllo world!
Code b:
Copy code The code is as follows:
<?php echo'hello\n';//unix系统使用\n;windows系统下\r\n echo'world!'; ?> 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!