Method of filtering html tags in form submission by php

  • 2021-07-22 09:08:59
  • OfStack

In this paper, an example is given to describe the method of filtering html tags in form submission by php. Share it for your reference. The specific implementation method is as follows:

Sometimes the simple comment function we do will find that there are many html tags submitted, which will lead to 1 external connection of the page. Let's look at the html tag method for filtering form submission in php.

In recent comments, there are 1 post links submitted by robots, all of which are 1 junk comments. In order to reduce this unnecessary link content, you can actually use php to delete the html tag submitted by the form POST, so that the information submitted by the machine will not get the results they want. It can also reduce the number of messages from seo/seo. html "target=" _ blank " > Punishment of search engines.

Here to remove < br/ > Labels, for example:

There are some situations that we need to get rid of < br/ > Tag, you can use the str_replace function.

// Take out br Mark 
$str=str_replace("<br>","",$str);

Remove the html label:
This can be done using the strip_tags function.
$str= strip_tags($str);

Encapsulated as a function:
<?php
    function removehtml($str){
        $str=str_replace("<br>","",$str);
        return strip_tags($str);
    }
?>

I hope this article is helpful to everyone's php programming.


Related articles: