PHP implements the method of filtering HTML tags in form submission

Source: Internet
Author: User
Tags comments form post html tags

Sometimes the simple comment feature we do will find that there are a lot of HTML tags that will cause the page to have some external connection, so let's look at the HTML tagging method for filtering form submissions in PHP.

Some of the post links submitted by robots in recent comments are spam comments. In order to reduce this unnecessary link content appears, actually can use PHP to delete form Post submitted HTML tags, so the machine submitted information will not get the results they want. And can reduce the penalty from the seo/seo.html "target=" _blank > Search engine.

Here to remove the <br/> label as an example:

In some cases we need to remove the <br/> tag and use the Str_replace function.

The code is as follows://Remove BR mark
$str =str_replace ("<br>", "", $str);


To remove an HTML tag:
Can be done using the Strip_tags function.

Copy code code as follows: $str = Strip_tags ($STR);


Encapsulated into a function:

The code is as follows: <?php
function removehtml ($STR) {
$str =str_replace ("<br>", "", $str);
Return Strip_tags ($STR);
}
?>
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.