[PHP] PHP压缩html的函数 →→→→→进入此内容的聊天室

来自 , 2020-10-08, 写在 PHP, 查看 157 次.
URL http://www.code666.cn/view/1091660f
  1. //函数名: compress_html
  2. //参数: $string
  3. //返回值: 压缩后的$string
  4. function compress_html($string) {
  5.     $string = str_replace("\\r\\n", '', $string); //清除换行符
  6.     $string = str_replace("\\n", '', $string); //清除换行符
  7.     $string = str_replace("\\t", '', $string); //清除制表符
  8.     $pattern = array (
  9.                     "/> *([^ ]*) *</", //去掉注释标记
  10.                     "/[\\s]+/",
  11.                     "/<!--[\\\\w\\\\W\\r\\\\n]*?-->/",
  12.                     "/\\" /",
  13.                    "/ \\"/",
  14.                     "'/\\*[^*]*\\*/'"
  15.                     );
  16.     $replace = array (
  17.                     ">\\\\1<",
  18.                     " ",
  19.                     "",
  20.                     "\\"",
  21.                    "\\"",
  22.                     ""
  23.                     );
  24.     return preg_replace($pattern, $replace, $string);
  25. }
  26. //该片段来自于http://yuncode.net
  27.  

回复 "PHP压缩html的函数"

这儿你可以回复上面这条便签

captcha