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 &"<"
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
過濾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