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(str
HTML,Match.Value,"")
Next
RemoveHTML=strHTML
Set objRegExp = Nothing
End Function
'过滤图片正则表达式:
%>
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
str1 = "正3>在转到 ... ..."
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 &;"
"
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="\"
a=objregexp.replace(str,"")
objregexp.pattern="\<[^\<]+>"
movejs=objregexp.replace(a,"")
end function
'过滤html标签只剩
function filterhtml(byval fstring)
if isnull(fstring) or trim(fstring)="" then
filterhtml=""
exit function
end if
fstring = replace(fstring, "
", "[br]")
fstring = replace(fstring, "
", "[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]", "
")
filterhtml = fstring
end function
%>
文章来自:大学生校园网-VvSchool.CN 详文参考:vvschool/html/web/program/2009/0522/251.html