谁帮我写一个ASP过滤掉所有html代码的函数
过滤掉所有html代码包括<p><br>这些,还有空格全都过滤掉。甚至空白字符全都过滤掉。写成函数形式,谢谢...
过滤掉所有html代码 包括<p><br>这些,还有空格全都过滤掉。甚至空白字符全都过滤掉。写成函数形式,谢谢
展开
展开全部
Function RemoveHTML(strHTML)
if strHTMl="" or isnull(strHTML) then
exit Function
end if
StrHtml = Replace(StrHtml,vbCrLf,"")
StrHtml = Replace(StrHtml,Chr(13)&Chr(10),"")
StrHtml = Replace(StrHtml,Chr(13),"")
StrHtml = Replace(StrHtml,Chr(10),"")
StrHtml = Replace(StrHtml," ","")
StrHtml = Replace(StrHtml," ","")
Dim objRegExp, Match, Matches
Set objRegExp = New Regexp
objRegExp.IgnoreCase = True
objRegExp.Global = True
objRegExp.Pattern = "<style(.+?)/style>"
Set Matches = objRegExp.Execute(strHTML)
For Each Match in Matches
strHtml=Replace(strHTML,Match.Value,"")
Next
objRegExp.Pattern = "<script(.+?)/script>"
Set Matches = objRegExp.Execute(strHTML)
For Each Match in Matches
strHtml=Replace(strHTML,Match.Value,"")
Next
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
if strHTMl="" or isnull(strHTML) then
exit Function
end if
StrHtml = Replace(StrHtml,vbCrLf,"")
StrHtml = Replace(StrHtml,Chr(13)&Chr(10),"")
StrHtml = Replace(StrHtml,Chr(13),"")
StrHtml = Replace(StrHtml,Chr(10),"")
StrHtml = Replace(StrHtml," ","")
StrHtml = Replace(StrHtml," ","")
Dim objRegExp, Match, Matches
Set objRegExp = New Regexp
objRegExp.IgnoreCase = True
objRegExp.Global = True
objRegExp.Pattern = "<style(.+?)/style>"
Set Matches = objRegExp.Execute(strHTML)
For Each Match in Matches
strHtml=Replace(strHTML,Match.Value,"")
Next
objRegExp.Pattern = "<script(.+?)/script>"
Set Matches = objRegExp.Execute(strHTML)
For Each Match in Matches
strHtml=Replace(strHTML,Match.Value,"")
Next
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
追问
过滤不了& n b s p;这样的代码
追答
那是空格,你直接在接受的时候通过.tirm()过滤就可以了!
展开全部
function replaceHTML(str)
dim regEx
set regEx=New RegExp
regEx.Ignorecase=True
regEx.Global=True
regEx.Multiline=True
regEx.Pattern="<[\/]?\w+(\s+\w+\=[\"]?\w+[\"]?)*[\/]?>"
str=regEx.Replace(str,"")
replaceHTML=str
set regEx=nothing
End function
应该过滤的差不多了
dim regEx
set regEx=New RegExp
regEx.Ignorecase=True
regEx.Global=True
regEx.Multiline=True
regEx.Pattern="<[\/]?\w+(\s+\w+\=[\"]?\w+[\"]?)*[\/]?>"
str=regEx.Replace(str,"")
replaceHTML=str
set regEx=nothing
End function
应该过滤的差不多了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
那你就直接建个asp文件,在里面写函数就是了,加个<% %>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询