PHP implements the method of filtering HTML tags in form submission _php tips

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

This article illustrates the way PHP implements HTML tags in filtering form submissions. Share to everyone for your reference. The implementation methods are as follows:

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.

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

I hope this article will help you with your PHP program design.

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.