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

  • 相关阅读:
    20201215王馨瑶 实验一《Python程序设计》实验报告
    20201215第十六周学习总结
    python笔记
    信导笔记
    成绩调节
    2020-2021-1 20201226 《信息安全专业导论》第十三周学习总结
    链表(补交)
    2020-2021-1 20201226 《信息安全专业导论》第十二周学习总结
    Wireshark 实践
    ssh
  • 原文地址:https://www.cnblogs.com/ayanboke/p/10076212.html
Copyright © 2011-2022 走看看