Php malicious code filtering function
Public Function DecodeFilter (html, filter)
Html = LCase (html)
Filter = split (filter ,",")
For Each I In filter
Select Case I
Case "SCRIPT" 'removes all client scripts such as javascept, vbscript, jscript, js, vbs, event ,...
Html = exeRE ("(javascript | jscript | vbscript | vbs):", "#", html)
Html = exeRE ("</? Script [^>] *> "," ", html)
Html = exeRE ("on (mouse | exit | error | click | key)", "", html)
Case "TABLE": 'remove table <TABLE> <tr> <td> <th>
Html = exeRE ("</? Table [^>] *> "," ", html)
Html = exeRE ("</? Tr [^>] *> "," ", html)
Html = exeRE ("</? Th [^>] *> "," ", html)
Html = exeRE ("</? Td [^>] *> "," ", html)
Html = exeRE ("</? Tbody [^>] *> "," ", html)
Case "CLASS" 'remove Style class CLASS = ""
Html = exeRE ("(<[^>] +) class = [^ | ^>] * ([^>] *>)", "$1 $2 ", html)
Case "STYLE" 'remove style STYLE = ""
Html = exeRE ("(<[^>] +) style =" "[^" "] *" "([^>] *> )", "$1 $2", html)
Html = exeRE ("(<[^>] +) style = '[^'] * '([^>] *>)", "$1 $2 ", html)
Case "IMG" 'remove style = ""
Html = exeRE ("</? Img [^>] *> "," ", html)
Case "XML" 'remove XML <? Xml>
Html = exeRE ("<\\? Xml [^>] *> "," ", html)
Case "NAMESPACE" 'remove NAMESPACE <o> </o>
Html = exeRE ("<\/? [A-z] +: [^>] *> "," ", html)
Case "FONT" 'remove fonts <font> </font>
Html = exeRE ("</? Font [^>] *> "," ", html)
Html = exeRE ("</? A [^>] *> "," ", html)
Html = exeRE ("</? Span [^>] *> "," ", html)
Html = exeRE ("</? Br [^>] *> "," ", html)
Case "MARQUEE" 'Subtitle removal <marquee> </marquee>
Html = exeRE ("</? Marquee [^>] *> "," ", html)
Case "OBJECT" 'removes objects <object> <param> <embed> </object>
Html = exeRE ("</? Object [^>] *> "," ", html)
Html = exeRE ("</? Param [^>] *> "," ", html)
'Html = exeRE ("</? Embed [^>] *> "," ", html)
Case "EMBED"
Html = exeRE ("</? Embed [^>] *> "," ", html)
Case "DIV" 'removes objects <object> <param> <embed> </object>
Html = exeRE ("</? Div ([^>]) *> "," $1 ", html)
Html = exeRE ("</? P ([^>]) *> "," $1 ", html)
Case "ONLOAD" 'remove style = ""
Html = exeRE ("(<[^>] +) onload =" "[^" "] *" "([^>] *> )", "$1 $2", html)
Html = exeRE ("(<[^>] +) onload = '[^'] * '([^>] *>)", "$1 $2 ", html)
Case "ONCLICK" 'remove style = ""
Html = exeRE ("(<[^>] +) onclick =" "[^" "] *" "([^>] *> )", "$1 $2", html)
Html = exeRE ("(<[^>] +) onclick = '[^'] * '([^>] *>)", "$1 $2 ", html)
Case "ONDBCLICK" 'remove style = ""
Html = exeRE ("(<[^>] +) ondbclick =" "[^" "] *" "([^>] *> )", "$1 $2", html)
Html = exeRE ("(<[^>] +) ondbclick = '[^'] * '([^>] *>)", "$1 $2 ", html)
End Select
Next
'Html = Replace (html, "<table", "<")
'Html = Replace (html, "<tr", "<")
'Html = Replace (html, "<td", "<")
DecodeFilter = html
End Function