![[asp学习]怎样过滤html元素,第1张 [asp学习]怎样过滤html元素,第1张](/aiimages/%5Basp%E5%AD%A6%E4%B9%A0%5D%E6%80%8E%E6%A0%B7%E8%BF%87%E6%BB%A4html%E5%85%83%E7%B4%A0.png)
", 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代码,只保留文字
%>
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)