When submitting a form, we often find that some text breaks cannot be seen in the database. In this way, js calls may cause problems. Next I will introduce the method for filtering text breaks in php. When submitting a form, we often find that some text breaks cannot be seen in the database. In this way, js calls may cause problems. Next I will introduce the method for filtering text breaks in php.
Script ec (2); script
In the unix world, newlines are replaced by/n, but in windows,/r/n is used to reflect their differences. What's more interesting is that/r is used in mac. Therefore, unix/n, windows/r/n, and mac/r are used to run programs on different platforms. Below are some common methods for removing line breaks in PHP.
Method 1:
| The Code is as follows: |
|
|
$ Content = str_replace ("n", "", $ content );
Echo $ content; |
Method 2:
| The Code is as follows: |
|
|
Str_replace ("rn", "", $ str );
|
Method 3:
| The Code is as follows: |
|
|
$ Content = preg_replace ("/s/", "", $ content );
Echo $ content; |
About n, r, t
N soft press Enter: in Windows, it indicates a line break and returns to the start position of the next line. In Linux and unix, it only indicates a line break, but does not return to the start position of the next line.
R Soft Space: in Linux and unix, it indicates that the first position of the row is returned. In Mac OS, line breaks are displayed and returned to the start position of the next line, which is equivalent to n in Windows.
T-hop (move to the next column)
Many methods are available on the website. none of the results are available. generally, the n symbol cannot be replaced. If the n symbol is cleared, it will still wrap the line. Generally, the br tag is included in the source code and can be replaced directly.
| The Code is as follows: |
|
|
Function DeleteHtml ($ str)
{
$ Str = str_replace ("
"," ", $ Str );
$ Str = str_replace ("\ t", "", $ str );
$ Str = str_replace ("\ r \ n", "", $ str );
$ Str = str_replace ("\ r", "", $ str );
$ Str = str_replace ("\ n", "", $ str );
Return trim ($ str );
} |
Note: The Escape Character before n.
Filter html and line feed instances
| The Code is as follows: |
|
|
// $ Document should contain an HTML document.
$ Search = array ("' ] *?>. *? Script 'si ", // remove javascript
"'<[/!] *? [^ <>] *?> 'Si ", // remove the HTML Tag
"'([Rn]) [s] +'", // remove the white space
"'& (Quot | #34);' I", // replaces the HTML Object
"'& (Amp | #38);' I ",
"'& (Lt | #60);' I ",
"'& (Gt | #62);' I ",
"'& (Nbsp | #160);' I ",
"'& (Iexcl | #161);' I ",
"'& (Cent | #162);' I ",
"'& (Pound | #163);' I ",
"'& (Copy | #169);' I ",
"'& # (D +); 'E"); // run as PHP code
$ Replace = array ("", "", "\ 1", "," & "," <","> "," ", chr (161 ), chr (162), chr (163), chr (169), "chr (\ 1 )");
$ Text = preg_replace ($ search, $ replace, $ document );
?> |