1st writing methods:
Copy codeThe Code is as follows:
<? Php
Str_replace ("n", '', $ str );
?>
2nd writing methods:
Copy codeThe Code is as follows:
<? Php
Str_replace ("rn", '', $ str );
?>
3rd writing methods:
Copy codeThe Code is as follows:
<? Php
Preg_replace ("/s/", '', $ str );
?>
The following is a description:
First, let's talk about n, r, t
N soft carriage return:
In Windows, line breaks are displayed and returned to the beginning of the next line.
In Linux/unix, it only indicates line breaks, but does not return to the starting position of the next line.
R Soft Space:
In Linux/unix, return to the starting position of the row
In Mac OS, line breaks are represented and returned to the start position of the next line, which is equivalent to n in Windows.
T-hop (move to the next column)
Note:
They are valid in double quotes or delimiters, and are invalid in single quotes.
Rn is generally used together to represent the Enter key on the keyboard (in Linux and Unix). You can also use n (in Windwos) and press enter in Mac OS!
T indicates the TAB key on the keyboard.
Line feed characters in the file:
Windows: n
Linux/unix: rn
The following code demonstrates three common methods for removing line breaks from strings in PHP:
1. Use escape character Functions
Copy codeThe Code is as follows:
<? Php
$ Str = str_replace (array ("/r/n", "/r", "/n"), '', $ str );
?>
2. replace with a regular expression
Copy codeThe Code is as follows:
<? Php
$ Str = preg_replace ('// s */', '', $ str );
?>
3. PHP system constants are recommended.
Copy codeThe Code is as follows:
<? Php
$ Str = str_replace (PHP_EOL, '', $ str );
?>