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.
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.
The Code is as follows:
// Retrieve the br mark
$ Str = str_replace ("<br>", "", $ str );
Remove html tags:
You can use the strip_tags function.
Copy the Code as follows:
$ Str = strip_tags ($ str );
Encapsulated into a function:
The Code is as follows:
<? Php
Function removehtml ($ str ){
$ Str = str_replace ("<br>", "", $ str );
Return strip_tags ($ str );
}
?>