Use php to filter the code that may be used in html to introduce external dangerous content. Sometimes, users must submit html content to enrich the information published by users. of course, some codes that may cause messy page layout are also filtered out. The following is a reference clip: # The html published by the user. filter the dangerous code functionuh ($ str) {& nbsp; $ farrarray (& nbsp; s +, use php to filter the code that may be used in html to introduce external dangerous content. Sometimes, users must submit html content to enrich the information published by users. of course, some codes that may cause messy page layout are also filtered out.
The following is a reference clip:
# Html published by the user to filter dangerous code
Function uh ($ str)
{
$ Farr = array (
"// \ S +/", // filter unnecessary spaces
"/<(\/?) (Script | I? Frame | style | html | body | title | link | meta | \? | \ %) ([^>] *?)> /IsU ", // filter"/(<[^>] *) On [a-zA-Z] + \ s * = ([^>] *>)/isU ", // filter javascript on events
);
$ Tarr = array (
"",
"<\ 1 \ 2 \ 3>", // leave this field blank if you want to clear insecure labels directly.
"\ 1 \ 2 ",
);
$ Str = PReg_replace ($ farr, $ tarr, $ str );
Return $ str;
}