PHP壓縮html網頁代碼 (清除空格
有個不錯的方法就是壓縮HTML
現提供PHP 壓縮HTML函數
不廢話了
復制代碼代碼如下:
<?php
/**
* 壓縮html : 清除換行符
* @param $string
* @return 壓縮後的$string
* */
function compress_html($string) {
$string = str_replace("rn"
$string = str_replace("n"
$string = str_replace("t"
$pattern = array (
"/> *([^ ]*) *</"
"/[s]+/"
"/<!
"/" /"
"/ "/"
"
);
$replace = array (
">
" "
""
"""
"""
""
);
return preg_replace($pattern
}
?>
From:http://tw.wingwit.com/Article/program/PHP/201311/21130.html