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.
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
##Related learning recommendations :2. Create a new PHP document and define a paragraph of text, example: 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
$newline = array("\r\n","\n","\r");
##5. Use the str_replace() function to replace the newline character with
, example:
$br = str_replace($newline,'<br />',$display);
6. Save the above content and view the effect after replacement in the browser
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!