用户登录
用户注册

分享至

asp去除html的函数代码分析附实例说明

  • 作者: 时不我予61353468
  • 来源: 51数据库
  • 2020-08-08
asp去除html的函数代码分析附实例说明,

下面这段代码,不会替换ld<sad中间的<,所以内容仍然是正常的

复制代码 代码如下:

<%
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," ")
str=replace(str," ","")
str=replace(str," ","")
nohtml=str
set re=nothing
end function

response.write nohtml(str)
%>

结果为:
复制代码 代码如下:



不过下面的代码是不问的,直接看到<就忘后面无限制的匹配
复制代码 代码如下:

<%
Function dropHtml(Byval strHTML)
Dim objRegExp, Match, Matches
Set objRegExp = New Regexp
objRegExp.IgnoreCase = True
objRegExp.Global = True
'取闭合的<>
objRegExp.Pattern = "<.+?>"
'进行匹配
Set Matches = objRegExp.Execute(strHTML)
' 遍历匹配集合,并替换掉匹配的项目
For Each Match in Matches
strHtml=Replace(strHTML,Match.Value,"")
Next
dropHtml=strHTML
Set objRegExp = Nothing
End Function

response.write dropHtml(str)
%>

结果为:
复制代码 代码如下:


软件
前端设计
程序设计
Java相关