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代码的函数)