Asp过滤掉HTML标记方法汇总
作者:admin 日期:2008-05-14
'过滤掉HTML标记,同时截取相应的字符数
Function cutStr(str,strlen)
Dim re
Set re = new RegExp
re.IgnoreCase = True
re.Global = True
re.Pattern = "<(.[^>]*)>"
str = re.Replace(str,"")
set re = Nothing
str=Replace(str,chr(10),"")
str=Replace(str,chr(13),"")
str=Replace(str," ","")
str=Replace(str," ","")
str=Replace(str," ","")
Dim l,t,c,i
l = Len(str)
t = 0
For i = 1 to l
c = Abs(Asc(Mid(str,i,1)))
If c > 255 Then
t = t + 2
Else
t = t + 1
End If
If t >= strlen Then
cutStr = left(str,i) & "..."
Exit For
Else
cutStr = str
End If
Next
End Function
function nohtml(str)
dim re
Set re=new RegExp
re.IgnoreCase =true
re.Global=True
re.Pattern="(\<.[^\<]*\>)"
str=re.replace(str," ")
re.Pattern="(\<\/[^\<]*\>)"
str=re.replace(str," ")
nohtml=str
set re=nothing
end function
'清梦的过滤HTML标记
Function RemoveHTML(strHTML)
Dim objRegExp, Match, Matches
Set objRegExp = New Regexp
objRegExp.IgnoreCase = True
objRegExp.Global = True
objRegExp.Pattern = "<.+?>" '取闭合的<>
objRegExp.Pattern = "<img[\s\S]+>" '过滤图片
Set Matches = objRegExp.Execute(strHTML) '进行匹配
For Each Match in Matches '遍历匹配集合,并替换掉匹配的项目
strHtml=Replace(strHTML,Match.Value,"")
Next
RemoveHTML=strHTML
Set objRegExp = Nothing
End Function
'过滤所有HTML标记
Function DelHTML(strToFilter)
Dim strTemp
strTemp = strToFilter
While Instr(1,strTemp,"<") AND Instr(1, strTemp, ">")
strTemp = Left(strTemp, Instr(1, strTemp, "<")-1) & Right(strTemp, Len(strTemp)-Instr(1,strTemp, ">"))
WEnd
DelHTML = strTemp
End Function
'过滤所有HTML标记
Function ClearHtml(str)
Dim re
Set re = new RegExp
re.IgnoreCase = True
re.Global = True
re.Pattern = "<(.[^>]*)>"
str = re.Replace(str,"")
set re = Nothing
str=Replace(str,chr(10),"")
str=Replace(str,chr(13),"")
str=Replace(str," ","")
str=Replace(str," ","")
str=Replace(str," ","")
ClearHtml = str
End Function
Function LoseHtml(ContentStr)
Dim ClsTempLoseStr,regEx
ClsTempLoseStr = Cstr(ContentStr)
Set regEx = New RegExp
regEx.Pattern = "<\/*[^<>]*>"
regEx.IgnoreCase = True
regEx.Global = True
ClsTempLoseStr = regEx.Replace(ClsTempLoseStr,"")
LoseHtml = ClsTempLoseStr
End function
'清除HTML标记
Function clearHTMLCode(originCode)
Dim reg
Set reg = new RegExp
reg.Pattern = "<[^>]*>"
reg.Global = True
clearHTMLCode = reg.Replace(originCode, "")
End Function
广告位