zoukankan      html  css  js  c++  java
  • php 处理html标签的方法

    function DeleteHtml($str)
    {
      /*$str=preg_replace("/s+/", " ", $str); //过滤多余回车
      $str=preg_replace("/<[ ]+/si","<",$str); //过滤<__("<"号后面带空格)
      $str=preg_replace("/<!--.*?-->/si","",$str); //注释
      $str=preg_replace("/<(!.*?)>/si","",$str); //过滤DOCTYPE
      $str=preg_replace("/<(/?html.*?)>/si","",$str); //过滤html标签
      $str=preg_replace("/<(/?head.*?)>/si","",$str); //过滤head标签
      $str=preg_replace("/<(/?meta.*?)>/si","",$str); //过滤meta标签
      $str=preg_replace("/<(/?body.*?)>/si","",$str); //过滤body标签
      $str=preg_replace("/<(/?link.*?)>/si","",$str); //过滤link标签
      $str=preg_replace("/<(/?form.*?)>/si","",$str); //过滤form标签
      $str=preg_replace("/cookie/si","COOKIE",$str); //过滤COOKIE标签
      $str=preg_replace("/<(applet.*?)>(.*?)<(/applet.*?)>/si","",$str); //过滤applet标签
      $str=preg_replace("/<(/?applet.*?)>/si","",$str); //过滤applet标签
      $str=preg_replace("/<(style.*?)>(.*?)<(/style.*?)>/si","",$str); //过滤style标签
      $str=preg_replace("/<(/?style.*?)>/si","",$str); //过滤style标签
      $str=preg_replace("/<(title.*?)>(.*?)<(/title.*?)>/si","",$str); //过滤title标签
      $str=preg_replace("/<(/?title.*?)>/si","",$str); //过滤title标签
      $str=preg_replace("/<(object.*?)>(.*?)<(/object.*?)>/si","",$str); //过滤object标签
      $str=preg_replace("/<(/?objec.*?)>/si","",$str); //过滤object标签
      $str=preg_replace("/<(noframes.*?)>(.*?)<(/noframes.*?)>/si","",$str); //过滤noframes标签
      $str=preg_replace("/<(/?noframes.*?)>/si","",$str); //过滤noframes标签
      $str=preg_replace("/<(i?frame.*?)>(.*?)<(/i?frame.*?)>/si","",$str); //过滤frame标签
      $str=preg_replace("/<(/?i?frame.*?)>/si","",$str); //过滤frame标签
      $str=preg_replace("/<(script.*?)>(.*?)<(/script.*?)>/si","",$str); //过滤script标签
      $str=preg_replace("/<(/?script.*?)>/si","",$str); //过滤script标签
      $str=preg_replace("/javascript/si","Javascript",$str); //过滤script标签
      $str=preg_replace("/vbscript/si","Vbscript",$str); //过滤script标签
      $str=preg_replace("/on([a-z]+)s*=/si","On\1=",$str); //过滤script标签
      $str=preg_replace("/&#/si","&#",$str); //过滤script标签,如javAsCript:alert('aabb)*/

      //清除空格和换行
      $str = trim($str); //清除字符串两边的空格
      $str = strip_tags($str,""); //利用php自带的函数清除html格式
      $str = preg_replace("/ /","",$str); //使用正则表达式替换内容,如:空格,换行,并将替换为空。
      $str = preg_replace("/ /","",$str);
      $str = preg_replace("/ /","",$str);
      $str = preg_replace("/ /","",$str);
      $str = preg_replace("/ /","",$str);
      $str = preg_replace("/ /","",$str); //匹配html中的空格
      $str = preg_replace("/(s*?r?ns*?)+/","n",$str); //去除字符串内部的空行:
      $str = preg_replace('/($s*$)|(^s*^)/m', '',$str); //去除全部的空行,包括内部和头尾
      return trim($str);
    }

    转自:http://www.shuchengxian.com/article/691.html

  • 相关阅读:
    Silverlight搜索框 (Button inside TextBox)
    Silverlight的一个简单加载标志Loading...
    WCF “GenerateWcfClientFilesTask”任务意外失败
    C# 字符格式处理
    c# 链表结构(2)循环链表
    CSS技巧 — 不使用图片实现圆角、阴影、渐变等功能【转】
    Silverlight监听属性变化
    浅谈HTTP中Get与Post的区别 [转]
    asp.net本质论——HttpModule
    web.config文件自定义配置节的使用方法的一个简单例子
  • 原文地址:https://www.cnblogs.com/ayanboke/p/10076212.html
Copyright © 2011-2022 走看看