网站首页 手机版
 注册 登录
您现在的位置: 畅无忧设计 >> 网络编程 >> ASP教程 >> 正文
最新文章
· FSO 组件asp生成html静态页面碰到缓存
· asp实现长文章自动分页插件
· 在ASP中访问和更新Cookies集合
· ASP错误提示大全
· 学习ASP的几个观点
· ASP用两级联动下拉列表来显示大类和小
· ASP取当前页面地址和参数
· ASP删除记录的同时删除相关图片
· asp将查询结果导出到excel
· ASP批量导入Excel到Access或者Sql Se
热门文章
 化境ASP无组件上传类 - upload_5xs
 一个获取ACCESS数据库表名以及表名
 asp将查询结果导出到excel
 艾恩ASP无组件上传修改版
 ASP批量导入Excel到Access或者Sql 
 ASP读取数据库的Flash+JS图片切换特
 ASP用两级联动下拉列表来显示大类和
 ASP+JS实现网页歌曲连播、点播功能
 使用ASP重启服务器
 asp批量替换access数据库中指定字段
相关文章
没有相关文章
过滤HTML各种标签、样式、脚本的asp函数
来源:jorkin.reallydo.com 更新时间:2010/9/24 0:39:48 阅读次数:
字体:[ ] 我要投稿

<%
'过滤HTML各种标签样式脚本
'需要RegReplace函数

Function HTMLFilter(sHTML, sFilters)
If sHTML & "" = "" Then Exit Function
If sFilters & "" = "" Then sFilters = "SCRIPT,OBJECT"
Dim aFilters
aFilters = Split(UCase(sFilters), ",")
For i = 0 To UBound(aFilters)
Select Case UCase(Trim(aFilters(i)))
Case "JORKIN"
Do While InStr(sHTML, "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;") >0
sHTML = Replace(sHTML, "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", "&nbsp;&nbsp;&nbsp;&nbsp;")
Loop
Case "SCRIPT"
'// 去除脚本<scr ipt></scr ipt>及 onload 等
sHTML = RegReplace(sHTML, "<SCRIPT[\s\S]*?</SCRIPT>", "")
sHTML = RegReplace(sHTML, "\s[on].+?=\s+?([\""|\'])(.*?)\1", "")
sHTML = RegReplace(sHTML, "(JAVASCRIPT|JSCRIPT|VBSCRIPT|VBS):", "$1:")
Case "FIXIMG"
sHTML = RegReplace(sHTML, "<IMG.*?\sSRC=([^\""\'\s][^\""\'\s>]*).*?>", "<img src=$2 border=0>")
sHTML = RegReplace(sHTML, "<IMG.*SRC=([\""\']?)(.\1\S+).*?>", "<img src=$2 border=0>")
Case "TABLE"
'// 去除表格<table><tr><td><th>
sHTML = RegReplace(sHTML, "</?TABLE[^>]*>", "")
sHTML = RegReplace(sHTML, "</?TBODY[^>]*>", "")
sHTML = RegReplace(sHTML, "<(/?)TR[^>]*>", "<$1p>")
sHTML = RegReplace(sHTML, "</?TH[^>]*>", " ")
sHTML = RegReplace(sHTML, "</?TD[^>]*>", " ")
Case "CLASS"
'// 去除样式类class=""
sHTML = RegReplace(sHTML, "(<[^>]+) CLASS=[^ |^>]+([^>]*>)", "$1 $2")
sHTML = RegReplace(sHTML, "\sCLASS\s*?=\s*?([\""|\'])(.*?)\1", "")
Case "STYLE"
'// 去除样式style=""
sHTML = RegReplace(sHTML, "(<[^>]+) STYLE=[^ |^>]+([^>]*>)", "$1 $2")
sHTML = RegReplace(sHTML, "\sSTYLE\s*?=\s*?([\""|\'])(.*?)\1", "")
Case "XML"
'// 去除XML<?xml>
sHTML = RegReplace(sHTML, "<\\?XML[^>]*>", "")
Case "NAMESPACE"
'// 去除命名空间<o:p></o:p>
sHTML = RegReplace(sHTML, "<\/?[a-z]+:[^>]*>", "")
Case "FONT"
'// 去除字体<font></font>
sHTML = RegReplace(sHTML, "</?FONT[^>]*>", "")
Case "MARQUEE"
'// 去除字幕<marquee></marquee>
sHTML = RegReplace(sHTML, "</?MARQUEE[^>]*>", "")
Case "OBJECT"
'// 去除对象<object><param><embed></object>
sHTML = RegReplace(sHTML, "</?OBJECT[^>]*>", "")
sHTML = RegReplace(sHTML, "</?PARAM[^>]*>", "")
sHTML = RegReplace(sHTML, "</?EMBED[^>]*>", "")
Case "COMMENT"
'// 去除HTML注释, 会处理<script>和<style>内注释, 慎用
sHTML = RegReplace(sHTML, "<!--[\s\S]*?-->", "")
Case Else
'// 去除其它标签
sHTML = RegReplace(sHTML, "</?" & aFilters(i) & "[^>]*?>", "")
End Select
Next
HTMLFilter = sHTML
End Function
%>

<%
'功能:使用正则表示式对字符串进行替换

Function RegReplace(Str, PatternStr, RepStr)
    Dim NewStr, regEx
    NewStr = Str
    If IsNull(NewStr) Then
        RegReplace = ""
        Exit Function
    End If
    Set regEx = New RegExp
    regEx.IgnoreCase = True
    regEx.Global = True
    regEx.Pattern = PatternStr
    NewStr = regEx.Replace(NewStr, RepStr)
    RegReplace = NewStr
End Function
%>

  • 上一篇文章:
  • 下一篇文章:
  • 关于我们 - 联系我们 - 广告服务 - 在线投稿 - 友情链接 - 网站地图 - 版权声明
    CopyRight 2008-2010, CWYDESIGN.COM - 畅无忧设计, Inc. All Rights Reserved
    滇ICP备09005765号