php filter dangerous html function code

Source: Internet
Author: User
Keywords Network programming PHP tutorial
Tags beginning code css tutorial delete expression function html link

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);
}
?>

Related Article

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.