[asp学习]怎样过滤html元素

[asp学习]怎样过滤html元素,第1张

Function HTMLDecode(reString)Dim Str:Str=reStringIf Not IsNull(Str) Then Str = Replace(Str, "&", "&") Str = Replace(Str, ">", ">") Str = Replace(Str, "<", "<") Str = Replace(Str, " ", CHR(32))Str = Replace(Str, " ", CHR(9)) Str = Replace(Str, "    ", CHR(9)) Str = Replace(Str, """, CHR(34)) Str = Replace(Str, "'", CHR(39)) Str = Replace(Str, "", CHR(13)) Str = Replace(Str, "

", CHR(10)) HTMLDecode = StrEnd IfEnd Function'去掉html标签,去掉换行Function NoHtml(strText) Dim regEx Set regEx = New RegExp regEx.Global = True regEx.IgnoreCase = True regEx.Pattern = "\n" strText = regEx.Replace(strText,"") regEx.Pattern = "\r" strText = regEx.Replace(strText,"") regEx.Pattern = "(.*?)<\/scrīpt>" strText = regEx.Replace(strText,"") regEx.Pattern = "<(.+?)>" strText = regEx.Replace(strText,"")NoHtml = strTextEnd Function function strcurrency(str)str=mid(cstr(formatcurrency(str,2)),2) strcurrency=str end function

asp过滤所有html代码,可以用正则表达式写函数来完成。代码如下:

<%

'说明:自定义正则替换函数,直接引用RemoveHTML这个函数就可以

Function RemoveHTML(strHTML)

Dim objRegExp,Match,Matches,k

Set objRegExp = New Regexp

objRegExp.IgnoreCase = True

objRegExp.Global = True

objRegExp.Pattern = "<.+?>"

Set Matches = objRegExp.Execute(strHTML)

strHTML = objRegExp.Replace(strHTML,"")

RemoveHTML=strHTML

Set objRegExp = Nothing

End Function

'使用示例:

a="<div></p><p>文字内容</p><p></div>"

a=RemoveHTML(a)

response.write a'执行完后,会过滤掉所有html代码,只保留文字

%>


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/6116075.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-15
下一篇 2023-03-15

发表评论

登录后才能评论

评论列表(0条)

保存