The function _php technique of filtering dangerous HTML code with PHP

Source: Internet
Author: User
#用户发布的html, filtering Dangerous code
Function uh ($STR)
{
$farr = Array (
"/\\s+/",//filter Excess blank
"/< (\\/?) (scrīpt|i?frame|style|html|body|title|link|meta|\\?| \\%) ([^>]*?) >/isu ",//filter <scrīpt, etc. may introduce malicious content or malicious changes to display the layout of the code, if you do not need to insert flash, etc., you can also add <object filter
"/(<[^>]*) on[a-za-z]+\\s*= ([^>]*>)/isu",//filtering javascrīpt on Event

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

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

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.