php tutorial filtering dangerous html function code
1, delete html comments;
2, delete the script, link, object, embed, iframe, frame, frameset and have on the beginning, contains the page effects: [^;
3, delete css tutorial notes (to prevent the use of this to deceive delete expression, I do not know if there are other ways to cheat delete expression);
4, delete the expression expression;
Filtering dangerous html * /
function fillter_html ($ str) {
/ * Filter style tags * /
return preg_replace_callback (
/ * Filter style tag content * /
'/(<s*style[^>]*>)((??((?!<s*/s*styles*>).)*)(<s*/s*styles*>)?/i' ,
create_function ('$ str', 'return $ str [1]. fillter_css ($ str [2]). $ str [3];'),
preg_replace (
array (
/ * Delete html comment * /
'/<!--.*?-->/i',
/ * Delete tag: script, link, object, embed, iframe, frame, frameset * /
'/<s*(script|object|embed|link|i?frame(set)?)[^>]*>(.*?<s*/s*1s*>)?/i',
/ * Delete event, javascript protocol, css expression * /
expressions () [^>] *) +>? / i ',
),
'',
$ str
)
);
}
/ * Filter style body * /
function fillter_css ($ str) {
/ * Delete comment, javascript protocol, expression * /
return preg_replace (array ('/(/*((?!*/).)/ | / * | * /) / i', '/expressions*((.*?))?javascripts*:/ i ',),' ', $ str);
}
?>