Home > Backend Development > PHP Problem > How to replace newline characters in PHP

How to replace newline characters in PHP

coldplay.xixi
Release: 2023-03-03 19:42:01
Original
4522 people have browsed it

How to replace newline characters in php: First create a new PHP document and define the text; then save it, print it in the browser, and define an array containing the newline characters for all platforms; then use the [str_replace()] function , replace the newline character with [
]; finally save it and view the effect in the browser.

How to replace newline characters in PHP

php method to replace newlines:

1. Before writing a PHP script, you first need to know the On different platforms, the newline characters are different.

  • Widows system newline character: \r\n

  • Linux system newline character :\n

  • Mac system newline character:\r

How to replace newline characters in PHP

##Related learning recommendations :

php graphic tutorial

2. Create a new PHP document and define a paragraph of text, example:

How to replace newline characters in PHP

3. Save the above content, view and print it in the browser. The default line break character will not be displayed in the browser, because the browser understands the line break character in HTML and it should be


How to replace newline characters in PHP

4. Define an array that contains line breaks for all platforms. Example:

$newline = array("\r\n","\n","\r");
Copy after login

Note: Line breaks must use double quotes (" ") includes

How to replace newline characters in PHP##5. Use the str_replace() function to replace the newline character with
, example:

$br = str_replace($newline,&#39;<br />&#39;,$display);
Copy after login

How to replace newline characters in PHP6. Save the above content and view the effect after replacement in the browser

How to replace newline characters in PHP

Related video recommendations:
PHP programming from entry to proficiency

The above is the detailed content of How to replace newline characters 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