Php: How to filter html tags in Form submission

Source: Internet
Author: User
Tags form post

Php: How to filter html tags in Form submission

Sometimes the simple comment function we make will find that many html tags are submitted, which may cause some external connections to the page, let's take a look at the html Tag Method used to filter form submissions in php.

Some post links submitted by robots in recent comments are all spam comments. To reduce the unnecessary link content, you can use php to delete the html Tag submitted by form POST, so that the information submitted by the machine will not get the expected result. In addition, it can reduce penalties from seo/seo.html "target =" _ blank "> search engines.

Here, the <br/> label is removed as an example:

In some cases, we need to remove the <br/> label and use the str_replace function.

The Code is as follows:

// Retrieve the br mark
$ Str = str_replace ("<br>", "", $ str );


Remove html tags:
You can use the strip_tags function.

Copy the 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 );
}
?>

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.