PHP implements methods for filtering HTML tags in form submissions, form tags _php tutorials

Source: Internet
Author: User
Tags form post

PHP implements methods for filtering HTML tags in form submissions, form labels


The example in this paper describes how PHP implements HTML tags for filtering form submissions. Share to everyone for your reference. The implementation method is as follows:

Sometimes we do a simple comment function will find that there are a lot of HTML tags submitted, these labels will cause the page to have some external connection, let's look at the HTML tag method of filtering form submission in PHP.

Some of the post links submitted by robots in recent reviews are spam reviews. In order to reduce this unnecessary link content appears, actually can use PHP to delete the form post submission HTML tag, so the machine submits the information also does not have the result which they want. And can reduce the penalty from seo/seo.html "target=" _blank "> Search engine.

Here to remove
Label For example:

In some cases we need to remove
tag, you can use the Str_replace function.
Copy the Code Code as follows://Remove BR mark
$str =str_replace ("
"," ", $str);
To remove an HTML tag:
It can be done using the Strip_tags function.
Copy the Code code as follows: $str = Strip_tags ($STR);
Encapsulated as a function:
Copy the Code code as follows: <?php
function removehtml ($STR) {
$str =str_replace ("
"," ", $str);
Return Strip_tags ($STR);
}
?>

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


PHP Filters extra HTML tags for code

PHP filter the extra HTML tag code!
Nction filterhtml ($STR)
{
$str =stripslashes ($STR);

$str =preg_replace ("/\s+/", ", $str); Filter Excess Return
$str =preg_replace ("/[]+/si", ", $str); Filter __ (the "" number is followed by a space)

$str =preg_replace ("/\!--. *?-->/si", ", $str); Comments
$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 Body Tags
$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 applet Tags
$str =preg_replace ("/(\/?applet.*?) >/si ",", $str); Filter applet Tags

$str =preg_replace ("/(style.*?) > (. *?) (\/styl ... Remaining full text >>

Filter HTML parts tags with PHP

You can use the Strip_tags function to remove HTML tags, including removing font labels.
To give you an example, in the official PHP manual, you can also check the use of this function yourself
$text = '

Test paragraph.</p> other text</a> ';
echo Strip_tags ($text);
echo "\ n";
Echo strip_tags ($text, '

'); Allow

Label
?>
Output Result:
Test paragraph. Other text

Test paragraph.</p> Other text</a>
I hope you have a little help.

http://www.bkjia.com/PHPjc/895110.html www.bkjia.com true http://www.bkjia.com/PHPjc/895110.html techarticle PHP Implementation of the method of filtering the HTML tags in the form submission, form tags This article describes how PHP implements filtering the HTML tags in the form submission. Share to everyone for your reference. Concrete implementation ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.