Home > Backend Development > PHP Tutorial > How to implement php filtering of html tags in form submission_PHP tutorial

How to implement php filtering of html tags in form submission_PHP tutorial

WBOY
Release: 2016-07-13 10:16:35
Original
911 people have browsed it

How to implement php filtering of html tags in form submissions

Sometimes when we do a simple comment function, we will find that a lot of html tags are submitted, and these tags will cause the page to have some extraneous features. In the case of connection, let's take a look at the html tag method of filtering form submission in PHP.

There have been some post links submitted by robots in recent comments, which are all spam comments. In order to reduce the appearance of this unnecessary link content, you can actually use php to delete the html tags submitted by the form POST, so that the information submitted by the machine will not get the results they want. And it can reduce penalties from seo/seo.html" target="_blank">search engines.

Here is an example of removing the
tag:

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

The code is as follows:

//Remove the br tag
$str=str_replace("
","",$str);


Remove html tag:
This can be done using the strip_tags function.

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/896779.htmlTechArticlephp method to implement filtering html tags in form submissions Sometimes when we make a simple comment function, we will find that there are many submissions html tags, these tags will cause some external connections on the page,...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template