Php implements the html Tag filtering method in Form submission, form tag
This example describes how to filter html tags in Form submission in php. Share it with you for your reference. The specific implementation method is as follows:
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.
Copy codeThe Code is as follows: // retrieve the br tag
$ Str = str_replace ("<br>", "", $ str );
Remove html tags:
You can use the strip_tags function.
Copy codeThe Code is as follows: $ str = strip_tags ($ str );
Encapsulated into a function:
Copy codeThe Code is as follows: <? Php
Function removehtml ($ str ){
$ Str = str_replace ("<br>", "", $ str );
Return strip_tags ($ str );
}
?>
I hope this article will help you with php programming.
Php code for filtering redundant html tags
Php code for filtering redundant html tags!
Nction filterhtml ($ str)
{
$ Str = stripslashes ($ str );
$ Str = preg_replace ("// \ s +/", '', $ str); // filter excess carriage returns
$ Str = preg_replace ("/[] +/si", '', $ str); // filter _ (" "with spaces)
$ Str = preg_replace ("/\! --.*? -->/Si ",'', $ str); // comment
$ Str = preg_replace ("/(\!. *?)> /Si ",'', $ str); // filter DOCTYPE
$ Str = preg_replace ("/(\/? Html. *?)> /Si ",'', $ str); // filter html tags
$ Str = preg_replace ("/(\/? Head. *?)> /Si ",'', $ str); // Filter head tags
$ Str = preg_replace ("/(\/? Meta. *?)> /Si ",'', $ str); // filter meta tags
$ Str = preg_replace ("/(\/? Body. *?)> /Si ",'', $ str); // filter the body tag
$ Str = preg_replace ("/(\/? Link. *?)> /Si ",'', $ str); // filter link tags
$ Str = preg_replace ("/(\/? Form. *?)> /Si ",'', $ str); // Filter form labels
$ Str = preg_replace ("/cookie/si", "COOKIE", $ str); // filter COOKIE tags
$ Str = preg_replace ("/(applet. *?)> (.*?) (\/Applet. *?)> /Si ",'', $ str); // filter the applet tag
$ Str = preg_replace ("/(\/? Applet. *?)> /Si ",'', $ str); // filter the applet tag
$ Str = preg_replace ("/(style. *?)> (.*?) (\/Styl ...... remaining full text>
Filter html tags using php
You can use the strip_tags function to remove html tags, including removing Font tags.
For example, you can check the usage of this function in the official php manual.
<? Php
$ Text = '<p> Test paragraph. </p> <! -- Comment --> <a href = "# fragment"> Other text </a> ';
Echo strip_tags ($ text );
Echo "\ n ";
Echo strip_tags ($ text, '<p> <a>'); // allow <p> and <a> tags
?>
Output result:
Test paragraph. Other text
<P> Test paragraph. </p> <a href = "# fragment"> Other text </a>
I hope it will be helpful to you.