数据载入中,请稍等...
    数据载入中,请稍等...
博客公告
    数据载入中,请稍等...
时间记忆
    数据载入中,请稍等...
博客登陆
最新日志
    数据载入中,请稍等...
最新评论
    数据载入中,请稍等...
最新留言
    数据载入中,请稍等...
博客相册
博客好友
    数据载入中,请稍等...
友情连接
博客统计
    数据载入中,请稍等...
用正则表达式过滤掉html的一些标签 | 2007-5-7 2:13:00
<%  
  '/*   函数名称:Zxj_ReplaceHtml ClearHtml  
  '/*   函数语言:VBScript   Language    
  '/*   作  用:清除文件HTML格式函数  
  '/*   传递参数:Content   (注:需要进行清除的内容)  
  '/*   函数作者:张晓军(古城童话) QQ:382511147  
  '/*   函数说明:正则匹配(正则表达式)模式进行数据匹配替换  
   
  Function   ClearHtml(Content)  
  Content=Zxj_ReplaceHtml("&#[^>]*;",   "",   Content)  
  Content=Zxj_ReplaceHtml("</?marquee[^>]*>",   "",   Content)  
  Content=Zxj_ReplaceHtml("</?object[^>]*>",   "",   Content)  
  Content=Zxj_ReplaceHtml("</?param[^>]*>",   "",   Content)  
  Content=Zxj_ReplaceHtml("</?embed[^>]*>",   "",   Content)  
  Content=Zxj_ReplaceHtml("</?table[^>]*>",   "",   Content)  
  Content=Zxj_ReplaceHtml("&nbsp;","",Content)  
  Content=Zxj_ReplaceHtml("</?tr[^>]*>",   "",   Content)  
  Content=Zxj_ReplaceHtml("</?th[^>]*>","",Content)  
  Content=Zxj_ReplaceHtml("</?p[^>]*>","",Content)  
  Content=Zxj_ReplaceHtml("</?a[^>]*>","",Content)  
  Content=Zxj_ReplaceHtml("</?img[^>]*>","",Content)  
  Content=Zxj_ReplaceHtml("</?tbody[^>]*>","",Content)  
  Content=Zxj_ReplaceHtml("</?li[^>]*>","",Content)  
  Content=Zxj_ReplaceHtml("</?span[^>]*>","",Content)  
  Content=Zxj_ReplaceHtml("</?div[^>]*>","",Content)  
  Content=Zxj_ReplaceHtml("</?th[^>]*>",   "",   Content)  
  Content=Zxj_ReplaceHtml("</?td[^>]*>",   "",   Content)  
  Content=Zxj_ReplaceHtml("</?script[^>]*>",   "",   Content)  
  Content=Zxj_ReplaceHtml("(javascript|jscript|vbscript|vbs):",   "",   Content)  
  Content=Zxj_ReplaceHtml("on(mouse|exit|error|click|key)",   "",   Content)  
  Content=Zxj_ReplaceHtml("<\\?xml[^>]*>",   "",   Content)  
  Content=Zxj_ReplaceHtml("<\/?[a-z]+:[^>]*>",   "",   Content)  
  Content=Zxj_ReplaceHtml("</?font[^>]*>",   "",   Content)  
  Content=Zxj_ReplaceHtml("</?b[^>]*>","",Content)  
  Content=Zxj_ReplaceHtml("</?u[^>]*>","",Content)  
  Content=Zxj_ReplaceHtml("</?i[^>]*>","",Content)  
  Content=Zxj_ReplaceHtml("</?strong[^>]*>","",Content)  
  ClearHtml=Content  
  End   Function  
   
  Function   Zxj_ReplaceHtml(patrn,   strng,content)  
  IF   IsNull(content)   Then  
  content=""  
  End   IF  
  Set   regEx   =   New   RegExp '   建立正则表达式。  
  regEx.Pattern   =   patrn '   设置模式。  
  regEx.IgnoreCase   =   true             '   设置忽略字符大小写。  
  regEx.Global   =   True '   设置全局可用性。  
  Zxj_ReplaceHtml=regEx.Replace(content,strng) '   执行正则匹配  
  End   Function  
  %>  
   
   
  将以上代码保存为 HtmlModify.asp   以后在需要清除HTML的文件中使用  
  <!--#i nclude   file=HtmlModify.asp-->  
  调用函数 ClearHtml() 即可  
   
  使用方法为  ClearHtml(Content)   其中   Content 为欲清除的代码存放的变量  
发表评论:
数据载入中,请稍等...

超音速工作室 版权所有
Powered by Oblog.