预览模式: 普通 | 列表

Asp过滤掉HTML标记方法汇总

'过滤掉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,"&nbsp;","")
 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

查看更多...

Tags: asp

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 3432

正则表达式语法

一个正则表达式就是由普通字符(例如字符 a 到 z)以及特殊字符(称为元字符)组成的文字模式。该模式描述在查找文字主体时待匹配的一个或多个字符串。正则表达式作为一个模板,将某个字符模式与所搜索的字符串进行匹配。

查看更多...

Tags: 正则表达式

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 2582

 广告位

↑返回顶部↑