Asp過(guò)濾Html代碼方法一
Function RemoveHTML(strHTML)
Dim objRegExp, Match, Matches
Set objRegExp = New Regexp
objRegExp.IgnoreCase = True
objRegExp.Global = True
'取閉合的<>
objRegExp.Pattern = "<.+?>"
'進(jìn)行匹配
Set Matches = objRegExp.Execute(strHTML)
' 遍歷匹配集合,并替換掉匹配的項(xiàng)目
For Each Match in Matches
strHtml=Replace(strHTML,Match.Value,"")
Next
RemoveHTML=strHTML
Set objRegExp = Nothing
End Function
過(guò)濾圖片正則表達(dá)式
<img.+?>
Asp過(guò)濾Html代碼方法二
Function delHtml(strHtml)
Dim objRegExp, strOutput
Set objRegExp = New Regexp ' 建立正則表達(dá)式
objRegExp.IgnoreCase = True ' 設(shè)置是否區(qū)分大小寫
objRegExp.Global = True '是匹配所有字符串還是只是第一個(gè)
objRegExp.Pattern = "(<[a-zA-Z].*?>)|(<[\/][a-zA-Z].*?>)" ' 設(shè)置模式引號(hào)中的是正則表達(dá)式,用來(lái)找出html標(biāo)簽
strOutput = objRegExp.Replace(strHtml, "") '將html標(biāo)簽去掉
strOutput = Replace(strOutput, "<", "<") '防止非html標(biāo)簽不顯示
strOutput = Replace(strOutput, ">", ">")
delHtml = strOutput
Set objRegExp = Nothing
End Function
'srt1是你要去除html代碼字符串,可以其它任何地方讀取過(guò)來(lái)。
str1 = "<meta http-equiv=""refresh"" content=""0;URL=apple/default.htm""><title>正</3>在轉(zhuǎn)到 ... ...</title>"
'應(yīng)用函數(shù)
Response.Write(delHtml(str1))
Asp過(guò)濾Html代碼方法三
轉(zhuǎn)化html標(biāo)簽為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 &"<"
case ">" : coder = coder &">"
case "&" : coder = coder &"&"
case chr(9) : coder = coder &" "
case chr(13) : coder = coder &"<br>"
case chr(32) : coder = coder &" "
case chr(34) : coder = coder &"""
case chr(39) : coder = coder &"'"
case else : coder = coder & mid(str,i,1)
end select
next
end function
過(guò)濾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
過(guò)濾html標(biāo)簽只剩<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]")
'過(guò)濾html標(biāo)簽
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