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

How to implement php filtering of html tags in form submission, form tag_PHP tutorial

WBOY
Release: 2016-07-13 10:17:00
Original
915 people have browsed it

php method to implement filtering html tags in form submission, form tags

The example in this article describes the method of filtering html tags in form submission in PHP. Share it with everyone for your reference. The specific implementation method is as follows:

Sometimes when we do a simple comment function, we will find that a lot of html tags are submitted. These tags will cause some external connections on the page. Let's take a look at how to filter the html tags submitted by the form 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.

Copy code 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 code The code is as follows:
$str= strip_tags($str);

Encapsulated into a function:
Copy code The code is as follows:
Function removehtml($str){
           $str=str_replace("
","",$str);
          return strip_tags($str);
}
?>

I hope this article will be helpful to everyone’s PHP programming design.

php code to filter redundant html tags

php code to filter redundant html tags!
 nction filterhtml($str)
 {
 $str=stripslashes($str);

 $str=preg_replace("/\s+/", ' ', $str); //Filter excess carriage returns
$str=preg_replace("/[ ]+/si",'',$str); //Filter __("" followed by a space)

$ str=preg_replace("/\!--.*?-->/si",'',$str); //Comment
 $str=preg_replace("/(\!.*?)> /si",'',$str); //Filter DOCTYPE
 $str=preg_replace("/(\/?html.*?)>/si",'',$str); //Filter html tag
 $str=preg_replace("/(\/?head.*?)>/si",'',$str); //Filter head tag
 $str=preg_replace("/( \/?meta.*?)>/si",'',$str); //Filter meta tags
 $str=preg_replace("/(\/?body.*?)>/si" ,'',$str); //Filter body tag
 $str=preg_replace("/(\/?link.*?)>/si",'',$str); //Filter link tag
 $str=preg_replace("/(\/?form.*?)>/si",'',$str); //Filter form tag
 $str=preg_replace("/cookie/si ","COOKIE",$str); //Filter COOKIE tags

 $str=preg_replace("/(applet.*?)>(.*?)(\/applet.*?)> ;/si",'',$str); //Filter applet tags
 $str=preg_replace("/(\/?applet.*?)>/si",'',$str); / /Filter applet tags

 $str=preg_replace("/(style.*?)>(.*?)(\/styl...the rest of the text>>

Use php to filter html partial tags

You can use the strip_tags function to remove html tags, including removing font tags
I will give you an example, it is in the official PHP manual. You can also check the usage of this function yourself
$ text = '

Test paragraph.

Other text';
echo strip_tags( $text);
echo "\n";
echo strip_tags($text, '

'); //Allow

, tags
?>
Output result:
Test paragraph. Other text

Test paragraph.

Other text
Hope it’s helpful to you

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/895110.htmlTechArticleHow to implement filtering html tags in form submission in php. Form tags This article describes the example of php implementing filtering html in form submission. label method. Share it with everyone for your reference. Specific implementation...
Related labels:
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