当然这应该属于正常过滤手法,而还有一种过滤html标签的最终极手法,则是将一对尖括号及尖括号中的所有字符均替换不显示,该方法对于内容中必须描述有关尖括号内容过滤过头了。
不过,总归是有需要将所有尖括号中内容全部替换的时候,很显然是需要进行正则的,有两种代码,第一种如下:
复制代码 代码如下:
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
第二种:
复制代码 代码如下:
function nohtml(str)
dim re
set re=new regexp
re.ignorecase =true
re.global=true
re.pattern="<(.[^>]*)>"
str=re.replace(str,"")
nohtml=str
set re=nothing
end function
简单的应用:
function nohtml(str)
dim re
set re=new regexp
re.ignorecase =true
re.global=true
re.pattern="]*)>"
str=re.replace(str,"")
nohtml=str
set re=nothing
end function
alert(nohtml("www.jb51.net硕编程"))
[ctrl+a 全选 注:如需引入外部js需刷新才能执行]
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!