asp去除html的函数代码分析附实例说明
程序员文章站
2022-07-01 23:26:51
下面这段代码,不会替换ld
<%
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
下面这段代码,不会替换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
上一篇: 2018-08-14 中文代码之Spring Boot实现简单REST服务
下一篇: C# 基本语法