加入收藏 | 设为首页 | 会员中心 | 我要投稿 汽车网 (https://www.0577qiche.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > Asp教程 > 正文

asp清除html的函数代码分析

发布时间:2023-10-17 10:15:17 所属栏目:Asp教程 来源:
导读:下面这段代码,不会替换ld<sad中间的<,所以内容仍然是正常的
复制代码 代码如下:
<%
function nohtml(str)
dim re
Set re=new RegExp
re.IgnoreCase =true
re.Global=True
re.Pattern="(/<.[^/<]*/>)"
str
下面这段代码,不会替换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
str="<title>sadjksjdl错新站长站欢迎你sajdljsald<sadsadsad<br>" '这里是测试
response.write nohtml(str)
%>

结果为:
复制代码 代码如下:
sadjksjdl错新站长站欢迎你sajdljsald<sadsadsad

不过下面的代码是不问的,直接看到<就忘后面无限制的匹配
复制代码 代码如下:
<%
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
str="<title>sadjksjdl错新站长站欢迎你sajdljsald<sadsadsad<br>" '这里是测试
response.write dropHtml(str)
%>

结果为:
复制代码 代码如下:
sadjksjdl错新站长站欢迎你sajdljsald

(编辑:汽车网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章