zoukankan      html  css  js  c++  java
  • php 去掉html中的空格和换行的方法

    /*
    +----------------------------------------------------------
     * 去掉html中的空格和换行的方法
    +----------------------------------------------------------
     */
    function delhtml($str)
    {
        $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('# #','',$str);
        $str = preg_replace('/s+/u', '',$str);
        $str = preg_replace("/[sv".chr(163).chr(160)."]+$/","",$str);
        $str = str_replace(array(" "," ","	","
    ","
    "," "), '', $str);
        $str = str_replace(chr(194) . chr(160), "-", $str);
        return trim($str); //返回字符串
    }

    可以去掉word导入的内容中的空格喔。

  • 相关阅读:
    c/cpp枚举练习
    数据类型的标识
    引用变量
    cocos2dx 3.3 笔记
    希望获取到页面中所有的checkbox怎么做?
    如何判断某变量是否为数组数据类型?
    驼峰函数写法
    trim()函数
    js 获取页面可视区域宽高
    全屏滚动插件
  • 原文地址:https://www.cnblogs.com/zhaoying/p/15425145.html
Copyright © 2011-2022 走看看