==========标题:ASP语法必学:过滤HTML的多种方法 ==========时间:2014-04-26 16:37:31 ==========来源:http://www.jtdx.cn/wap/index.asp?act=pl&id=335 ==========以下为正文
Asp过滤Html代码方法一

Function RemoveHTML(strHTML)
Dim objRegExp, Match, Matches
Set objRegExp = New Regexp
objRegExp.IgnoreCase = True
objRegExp.Global = True
'取闭合的<>
objRegExp.Pattern = "<.+?>"
'进行匹配
Set Matches = objRegExp.Execute(strHTML)
' 遍历匹配集合,并替换掉匹配的项目
For Each Match in Matches
strHtml=Replace(strHTML,Match.Value,"")
Next
RemoveHTML=strHTML
Set objRegExp = Nothing
End Function

过滤图片正则表达式

<img.+?>

Asp过滤Html代码方法二

Function delHtml(strHtml)

Dim objRegExp, strOutput
Set objRegExp = New Regexp ' 建立正则表达式

objRegExp.IgnoreCase = True ' 设置是否区分大小写
objRegExp.Global = True '是匹配所有字符串还是只是第一个
objRegExp.Pattern = "(<[a-zA-Z].*?>)|(<[\/][a-zA-Z].*?>)" ' 设置模式引号中的是正则表达式,用来找出html标签

strOutput = objRegExp.Replace(strHtml, "") '将html标签去掉
strOutput = Replace(strOutput, "<", "<") '防止非html标签不显示
strOutput = Replace(strOutput, ">", ">")
delHtml = strOutput

Set objRegExp = Nothing
End Function

'srt1是你要去除html代码字符串,可以其它任何地方读取过来。
str1 = "<meta http-equiv=""refresh"" content=""0;URL=apple/default.htm""><title>正</3>在转到 ... ...</title>"
'应用函数
Response.Write(delHtml(str1))

Asp过滤Html代码方法三

转化html标签为code代码

function coder(str)
    dim i
    if isnull(str) then : coder="" : exit function : end if
    for i = 1 to len(str)
      select case mid(str,i,1)
        case "<"       : coder = coder &"&lt;"
        case ">"       : coder = coder &"&gt;"     
        case "&"       : coder = coder &"&amp;"
        case chr(9)    : coder = coder &"&nbsp; &nbsp; "
        case chr(13) : coder = coder &"<br>"
        case chr(32) : coder = coder &"&nbsp;"
        case chr(34) : coder = coder &"&quot;"
        case chr(39) : coder = coder &"&#39;"
        case else      : coder = coder & mid(str,i,1)
      end select
    next
end function


过滤javascript字符

function movejs(str)
dim objregexp,str1
    
set objregexp=new regexp
    
objregexp.ignorecase =true
    
objregexp.global=true
    
    
objregexp.pattern="\<script.+?\<\/script\>"
    
a=objregexp.replace(str,"")
    
objregexp.pattern="\<[^\<]+>"
    
movejs=objregexp.replace(a,"")
end function


过滤html标签只剩<br>

function filterhtml(byval fstring)
      if isnull(fstring) or trim(fstring)="" then
          filterhtml=""
          exit function
      end if
    
      fstring = replace(fstring, "<br />", "[br]")
      fstring = replace(fstring, "<br>", "[br]")
    
      '过滤html标签
      dim re
      set     re = new     regexp
      re.ignorecase=true
      re.global=true
      re.pattern="<(.+?)>"
      fstring = re.replace(fstring, "")
      set     re=nothing
    
      fstring = replace(fstring, "[br]", "<br />")
      filterhtml = fstring
end function
==========更多关于《ASP语法必学:过滤HTML的多种方法》的评论/回复, ========== 请关注:http://www.jtdx.cn/wap/index.asp?act=pl&id=335