Summary of replacing line breaks in PHP. Methods for replacing line breaks in PHP summary methods for replacing line breaks in php. There are three solutions for php. 1. use str_replace to replace the line feed $ strstr_replace (array (rn, r, PHP ).
In summary, there are three methods for replacing line breaks in php.
1. use str_replace to replace the line feed.
$str=str_replace(array("\r\n","\r","\n"),"",$str);
2. use regular expression replacement
$str=preg_replace('//s*/','',$str);
3. use variables defined in php (recommended)
$str=str_replace(PHP_EOL,'',$str);
Switch to a line feed that can be displayed on the front-end. for directions of the nl2br, refer to the php Manual.
$str="abefc";echo nl2br($str);
The output html code is as follows:
A
B
E
F
C
Articles you may be interested in
- Php uses regular expressions to filter various tags, spaces, and line breaks.
- How does php convert the br line breaks in html to line breaks in text input?
- PHP compresses html webpage code (clear spaces, line breaks, tabs, comment tags)
- Css controls code for force-breaking and non-wrapping in English and Chinese
- Php string replacement function str_replace is faster than preg_replace
- PHP is replaced only once to control the number of replacements
- PHP compresses html webpage code to reduce the amount of network data transmitted, clear spaces, tabs, and comment mark
- In php, we use the curl post method to submit data and the get method to obtain webpage data.
In summary, there are three methods to replace line breaks in Composer php. 1. use str_replace to replace the newline $ str = str_replace (array ("\ r \ n", "\ r ","\...