教程集 www.jiaochengji.com
教程集 >  脚本编程  >  Asp.net  >  正文 asp 过滤html标签

asp 过滤html标签

发布时间:2016-09-26   编辑:jiaochengji.com
教程集为您提供asp 过滤html标签等资源,欢迎您收藏本站,我们将为您提供最新的asp 过滤html标签资源
这是四款asp 过滤html标签函数与方法,这些大全部都是利用正则表达式来过滤以<与>的数据,然后替换里面的东西,这样asp过滤html的函数不成功了。
<table style="background: #fb7" border="0" cellspacing="1" cellpadding="1" width="620" align="center"> <tbody> <tr> <td bgcolor="#ffe7ce" height="27" width="464"> 代码如下</td> <td style="cursor: pointer" bgcolor="#ffe7ce" width="109" align="center" onclick="doCopy('copy2917')">复制代码</td> </tr> <tr> <td style="padding-bottom: 10px; padding-left: 10px; padding-right: 10px; padding-top: 10px" id="copy2917" class="copyclass" bgcolor="#ffffff" valign="top" colspan="2">

function htmlencode(text)
{
return text.replace(/&/g, '&amp').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
}

function htmldecode(text)
{
return text.replace(/&amp;/g, '&').replace(/&quot;/g, '"').replace(/&lt;/g, '<').replace(/&gt;/g, '>');
}

</td> </tr> </tbody> </table>


'方法二

<table style="background: #fb7" border="0" cellspacing="1" cellpadding="1" width="620" align="center"> <tbody> <tr> <td bgcolor="#ffe7ce" height="27" width="464"> 代码如下</td> <td style="cursor: pointer" bgcolor="#ffe7ce" width="109" align="center" onclick="doCopy('copy6481')">复制代码</td> </tr> <tr> <td style="padding-bottom: 10px; padding-left: 10px; padding-right: 10px; padding-top: 10px" id="copy6481" class="copyclass" bgcolor="#ffffff" valign="top" colspan="2">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</td> </tr> </tbody> </table>

'过滤html标签方 方法三

<table style="background: #fb7" border="0" cellspacing="1" cellpadding="1" width="620" align="center"> <tbody> <tr> <td bgcolor="#ffe7ce" height="27" width="464"> 代码如下</td> <td style="cursor: pointer" bgcolor="#ffe7ce" width="109" align="center" onclick="doCopy('copy7566')">复制代码</td> </tr> <tr> <td style="padding-bottom: 10px; padding-left: 10px; padding-right: 10px; padding-top: 10px" id="copy7566" class="copyclass" bgcolor="#ffffff" valign="top" colspan="2">

function filterhtml(strtofilter)
     dim objregexp, match, matches
     set objregexp = new regexp
     objregexp.ignorecase = true
     objregexp.global = true
     '取闭合的<>
     objregexp.pattern = "<. ?>"
     '进行匹配
     set matches = objregexp.execute(strtofilter)
     ' 遍历匹配集合,并替换掉匹配的项目
     for each match in matches
     strtofilter=replace(strtofilter,match.value,"")
     next
     filterhtml=strtofilter
     set objregexp = nothing
end function

'调用

str=filterhtml(str)

</td> </tr> </tbody> </table>

'过滤html标签方法四

<table style="background: #fb7" border="0" cellspacing="1" cellpadding="1" width="620" align="center"> <tbody> <tr> <td bgcolor="#ffe7ce" height="27" width="464"> 代码如下</td> <td style="cursor: pointer" bgcolor="#ffe7ce" width="109" align="center" onclick="doCopy('copy7433')">复制代码</td> </tr> <tr> <td style="padding-bottom: 10px; padding-left: 10px; padding-right: 10px; padding-top: 10px" id="copy7433" class="copyclass" bgcolor="#ffffff" valign="top" colspan="2">

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

</td> </tr> </tbody> </table>

 

您可能感兴趣的文章:
php正则过滤html特殊字符
php正则过滤html标签、空格、换行符等的代码示例
asp基础语法
php利用正则过滤链接、标签,空格,换行符程序
php删除字符串中html标签的函数
php用strip_tags完整去除所有html标签的实例分享
php删除html标签及字符串中html标签的代码
php正则过滤指定html标签示例
c#正则过滤图片标签 asp.net正则过滤的例子
php 防注入的一段代码(过滤参数)

[关闭]
~ ~