站长论坛

标题: asp利用正则去掉字符串中所有html内容 [打印本页]

作者: superadmin    时间: 2008-9-12 18:28
标题: asp利用正则去掉字符串中所有html内容
利用正则表达式去掉字符串中所有html内容,得到所有文本内容,去掉的内容有:div,img,超连接,script脚本等html内容。将以下例子保存为asp文件,运行一下就知道效果了。


<%
Function RemoveHTML( strText )
Dim RegEx

Set RegEx = New RegExp

RegEx.Pattern = "<[^>]*>"
RegEx.Global = True

RemoveHTML = RegEx.Replace(strText, "")
End Function

str="<html><body><a href=""a.asp"">打开</a><img src=""1.jpg""><div class=""a3"">aaa</div></body></html>"
response.write removehtml(str)
%>




欢迎光临 站长论坛 (http://www.tzlink.com/bbs/) Powered by Discuz! X3.2