PhpHtmlReplace input filtering security function _ PHP Tutorial

Source: Internet
Author: User
PhpHtmlReplace input filter security function. Copy the code as follows: $ rptype0 indicates that only the html tag is replaced. $ rptype1 indicates that the html tag is replaced and consecutive white spaces are removed. $ rptype2 indicates that the html tag is replaced at the same time. The code is as follows:


// $ Rptype = 0 indicates that only the html tag is replaced.
// $ Rptype = 1 indicates replacing the html tag and removing consecutive white spaces
// $ Rptype = 2 indicates replacing the html tag and removing all white spaces
// $ Rptype =-1 indicates that only the html dangerous tag is replaced.
Function HtmlReplace ($ str, $ rptype = 0)
{
$ Str = stripslashes ($ str );
If ($ rptype = 0)
{
$ Str = htmlspecialchars ($ str );
}
Else if ($ rptype = 1)
{
$ Str = htmlspecialchars ($ str );
$ Str = str_replace ("", '', $ str );
$ Str = ereg_replace ("[rnt] {1,}", '', $ str );
}
Else if ($ rptype = 2)
{
$ Str = htmlspecialchars ($ str );
$ Str = str_replace ("", '', $ str );
$ Str = ereg_replace ("[rnt]", '', $ str );
}
Else
{
$ Str = ereg_replace ("[rnt] {1,}", '', $ str );
$ Str = eregi_replace ('script', 'script', $ str );
$ Str = eregi_replace ("<[/] {0, 1} (link | meta | ifr | fra) [^>] *>", '', $ str );
}
Return addslashes ($ str );
}

The http://www.bkjia.com/PHPjc/322099.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/322099.htmlTechArticle code is as follows: // $ rptype = 0 indicates that only the html tag is replaced. // $ rptype = 1 indicates that the html tag is replaced and consecutive white spaces are removed. // $ rptype = 2 indicates that the html tag is replaced at the same time...

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.