Php: how to filter html tags in form submission _ PHP Tutorial

Source: Internet
Author: User
Tags form post
Php implements the html tag filtering method in form submission. Php implements the html tag filtering method in form submission. sometimes some html tags are submitted in the simple comment function, which may cause some external connections to the page, 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.

Remove it here
Tag:

In some cases, we need to remove
Tag. you can use the str_replace function.

The code is as follows:

// Retrieve the br Mark
$ Str = str_replace ("
"," ", $ Str );


Remove html tags:
You can use the strip_tags function.

The code is as follows:

$ Str = strip_tags ($ str );


Encapsulated into a function:

The code is as follows:

Function removehtml ($ str ){
$ Str = str_replace ("
"," ", $ Str );
Return strip_tags ($ str );
}
?>

Sometimes, when we make a simple comment, we will find that many html tags are submitted. these tags will cause some external connections to the page ,...

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.