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.
I hope this article will be helpful to everyone’s PHP programming design.
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>>
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';'); //Allow , tags Test paragraph.
?>
Output result:
Test paragraph. Other text
Hope it’s helpful to you