Summary of methods to replace newline characters in PHP
Summary of methods to replace newline characters in PHP, PHP has three methods to solve it.
1. Use str_replace to replace newlines
$str=str_replace(array("\r\n","\r","\n"),"",$str);
Copy after login
2. Use regular replacement
$str=preg_replace('//s*/','',$str);
Copy after login
3. Use variables defined by php (recommended)
$str=str_replace(PHP_EOL,'',$str);
Copy after login
Convert to a line break that can be displayed in the front desk. For the direction function of nl2br, please refer to the PHP manual
$str="a
b
e
f
c";
echo nl2br($str);
Copy after login
The output html code is as follows:
a
b
e
f
c
Articles you may be interested in
- php code that uses regular rules to filter various tags, spaces, and line breaks
- How to wrap br in html with php Convert characters into line breaks in text input
- PHP compresses HTML web page code (clears spaces, newlines, tabs, comment marks)
- css controls forced line breaks and no line breaks in English and Chinese The code
- PHP string replacement function str_replace is faster than preg_replace
- PHP only replaces it once and controls the number of replacements
- PHP compresses html web page code to reduce the amount of network data transmission. Clear spaces, tabs, and comment marks
- Summary of how to submit data using curl's post and get to get web page data in PHP
http://www.bkjia.com/PHPjc/1072764.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1072764.htmlTechArticleA summary of the method of replacing line breaks in PHP. A summary of the methods of replacing line breaks in PHP. PHP has three methods to solve it. 1. Use str_replace to replace newlines $str=str_replace(array("rn","r","...