php压缩html代码的函数

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php压缩html代码的函数相关的知识,希望对你有一定的参考价值。

// 压缩html
function compress_html($string) {
    $string = str_replace("\r\n", ‘‘, $string);
    $string = str_replace("\n", ‘‘, $string);
    $string = str_replace("\t", ‘‘, $string);
    $pattern = array("/> *([^ ]*) *</", "/[\s]+/", "/<!--[\\w\\W\r\\n]*?-->/", "/\" /", "/ \"/", "‘/\*[^*]*\*/‘");
    $replace = array(">\\1<", " ", "", "\"", "\"", "");
    return preg_replace($pattern, $replace, $string);
}

好用不解释

以上是关于php压缩html代码的函数的主要内容,如果未能解决你的问题,请参考以下文章