PHP removes line breaks and sensitive html tags

Source: Internet
Author: User
Tags chr html tags

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: Copy code


$ Content = str_replace ("n", "", $ content );

Echo $ content;

Method 2:

The code is as follows: Copy code


Str_replace ("rn", "", $ str );

Method 3:

The code is as follows: Copy code


$ 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: Copy code

Function DeleteHtml ($ str)
{
$ Str = str_replace ("<br/>", "", $ 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: Copy code

<? Php
// $ Document should contain an HTML document.
 
$ Search = array ("'<script [^>] *?>. *? </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 );
?>

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.