有时候我们需要去除HTML标签只要里面的文字,如截取文章的前100个汉字作为文章的导读,这个时候我们只想要最前100个文字,HTML标签都要去掉。下面青岛星网跟大家分享:ASP去除所有HTML标签函数。
只取前100个文字最简单的ASP函数left即可。但是如何去除所有的HTML标签呢?
去除全部HTML标签的ASP函数Public Function ReplaceHTML(Textstr)
Dim Str, re
Str = Textstr
Set re = New RegExp
re.IgnoreCase = True
re.Global = True
re.Pattern = "]*)>"
Str = re.Replace(Str, "")
Set Re = Nothing
ReplaceHTML = Str
End Function
使用正则表达式过滤所有HTML标记加强版函数Public Function ReplaceHTML(Textstr)
Dim sStr, regEx
sStr = Textstr
Set regEx = New RegExp
regEx.IgnoreCase = True
regEx.Global = True
regEx.Multiline = True
' regEx.Pattern = "" '//想用就把注释去掉
' sStr = regEx.Replace(sStr, "")
regEx.Pattern = "
sStr = regEx.Replace(sStr, "")
regEx.Pattern = "
sStr = regEx.Replace(sStr, "")
regEx.Pattern = "\s[on].+?=([\""|\'])(.*?)\1"
sStr = regEx.Replace(sStr, "")
regEx.Pattern = "<(.[^>]*)>"
sStr = regEx.Replace(sStr, "")
Set regEx = Nothing
ReplaceHTML = sStr
End Function