• Asp正则表达式过滤标签html,style ,div,font,span,Object,iframe等

  • sowhy 于 2013/3/22 2:20:56 5001 次浏览 0 参与讨论
<%
'过滤 所有 html :

Function ReplaceHtml(ConStr)
    Dim tmpReStr, regEx
    tmpReStr = CStr(ConStr)
    Set regEx = New RegExp
    regEx.Pattern = "<\/*[^<>]*>"
    regEx.IgnoreCase = True
    regEx.Global = True
    tmpReStr = regEx.Replace(tmpReStr, "")
    ReplaceHtml = tmpReStr
End Function

'过滤 style :

Function ReplaceStyleTag(ConStr)
    Dim tmpReStr, regEx
    tmpReStr = CStr(ConStr)
    Set regEx = New RegExp
    regEx.Pattern = "(<style)+[^<>]*>[^\0]*(<\/style>)+"
    regEx.IgnoreCase = True
    regEx.Global = True
    tmpReStr = regEx.Replace(tmpReStr, "")
    ReplaceStyleTag = tmpReStr
    Set regEx = Nothing
End Function


'过滤 层 div :

Function ReplaceDivTag(ConStr)
    Dim tmpReStr, regEx
    tmpReStr = CStr(ConStr)
    Set regEx = New RegExp
    regEx.Pattern = "<(\/){0,1}div[^<>]*>"
    regEx.IgnoreCase = True
    regEx.Global = True
    tmpReStr = regEx.Replace(tmpReStr, "")
    ReplaceDivTag = tmpReStr
    Set regEx = Nothing
End Function



'过滤 链接 a :

Function ReplaceATag(ConStr)
    Dim tmpReStr, regEx
    tmpReStr = CStr(ConStr)
    Set regEx = New RegExp
    regEx.Pattern = "<(\/){0,1}a[^<>]*>"
    regEx.IgnoreCase = True
    regEx.Global = True
    tmpReStr = regEx.Replace(tmpReStr, "")
    ReplaceATag = tmpReStr
    Set regEx = Nothing
End Function


'过滤 字体 font :

Function ReplaceFontTag(ConStr)
    Dim tmpReStr, regEx
    tmpReStr = CStr(ConStr)
    Set regEx = New RegExp
    regEx.Pattern = "<(\/){0,1}font[^<>]*>"
    regEx.IgnoreCase = True
    regEx.Global = True
    tmpReStr = regEx.Replace(tmpReStr, "")
    ReplaceFontTag = tmpReStr
    Set regEx = Nothing
End Function


'过滤 span :

Function ReplaceSpanTag(ConStr)
    Dim tmpReStr, regEx
    tmpReStr = CStr(ConStr)
    Set regEx = New RegExp
    regEx.Pattern = "<(\/){0,1}span[^<>]*>"
    regEx.IgnoreCase = True
    regEx.Global = True
    tmpReStr = regEx.Replace(tmpReStr, "")
    ReplaceSpanTag = tmpReStr
    Set regEx = Nothing
End Function


'过滤 Object :

Function ReplaceObjectTag(ConStr)
    Dim tmpReStr, regEx
    tmpReStr = CStr(ConStr)
    Set regEx = New RegExp
    regEx.Pattern = "<object.*?/object>"
    regEx.IgnoreCase = True
    regEx.Global = True
    tmpReStr = regEx.Replace(tmpReStr, "")
    ReplaceObjectTag = tmpReStr
    Set regEx = Nothing
End Function


'过滤 iframe:

Function ReplaceIFrameTag(ConStr)
    Dim tmpReStr, regEx
    tmpReStr = CStr(ConStr)
    Set regEx = New RegExp
    regEx.Pattern = "(<iframe){1,}[^<>]*>[^\0]*(<\/iframe>){1,}"
    regEx.IgnoreCase = True
    regEx.Global = True
    tmpReStr = regEx.Replace(tmpReStr, "")
    ReplaceIFrameTag = tmpReStr
    Set regEx = Nothing
End Function


'过滤 script:

Function ReplaceScriptTag(ConStr)
    Dim tmpReStr, regEx
    tmpReStr = CStr(ConStr)
    Set regEx = New RegExp
    regEx.Pattern = "(<script){1,}[^<>]*>[^\0]*(<\/script>){1,}"
    regEx.IgnoreCase = True
    regEx.Global = True
    tmpReStr = regEx.Replace(tmpReStr, "")
    ReplaceScriptTag = tmpReStr
    Set regEx = Nothing
End Function


'过滤 Class :

Function ReplaceClassTag(ConStr)
    Dim tmpReStr, regEx
    tmpReStr = CStr(ConStr)
    Set regEx = New RegExp
    regEx.Pattern = "(class=){1,}(""|\'){0,1}\S+(""|\'|>|\s){0,1}"
    regEx.IgnoreCase = True
    regEx.Global = True
    tmpReStr = regEx.Replace(tmpReStr, "")
    ReplaceClassTag = tmpReStr
    Set regEx = Nothing
End Function
%>

参与讨论 0人

回复
  • 添加一条新的回复

    返回列表
  • 验证码: 验证码
  • HI,欢迎来到SEMCMS外贸网站管理系统
  • 注册 登录
  • SEMCMS公众号扫一扫加关注
    及时了解系统更新情况
  • SEMCMS公众号扫一扫加关注