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