PHP Filter Unsafe html_php Tutorial

Source: Internet
Author: User
PHP filter for unsafe HTMLUse PHP to filter the code in HTML that might be exploited to introduce external dangerous content. Sometimes, you need to let users submit HTML content,
To enrich the information that users post, of course, some of the code that might cause clutter in the Display page layout is also within the scope of filtering.


The following is a reference fragment:
#用户发布的html, filtering hazard codes
Function uh ($STR)
{
$farr = Array (
"/\s+/",
Filter Extra Blanks
"/< (\/?) (script|i?frame|style|html|body|title|link|meta|\?| \%) ([^>]*?) >/isu ",
Filter to join
"/(<[^>]*) on[a-za-z]+\s*= ([^>]*>)/isu",
Filtering the on event for JavaScript

);
$tarr = Array (
" ",
"<\\1\\2\\3>",//If you want to clear unsafe labels directly, you can leave this blank
"\\1\\2",
);

$str = Preg_replace ($farr, $tarr, $STR);
return $str;
}

http://www.bkjia.com/PHPjc/629758.html www.bkjia.com true http://www.bkjia.com/PHPjc/629758.html techarticle PHP Filters unsafe HTML by using PHP to filter the code in HTML that might be exploited to introduce external dangerous content. Sometimes, you need to let users submit HTML content in order to enrich the user's published information ...

  • 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.