1.å¦ä½ç¨phpå缩html代ç 并è¾åº
å¦ä½ç¨phpå缩html代ç 并è¾åº
å¦ä½ç¨phpå缩html代ç 并è¾åº
function compressHtml($string) { $matches = array(); preg_match_all('/(<(?输输出安卓源码 Xposed:pre|code)>.+?<\/(?:pre|code)>)+/is', $string, $matches); foreach ((array)$matches[1] as $k => $v) { $string = str_replace($v, "#{ $k}#", $string); } $string = str_replace("\r\n", '', $string); //æ¸ é¤æ¢è¡ç¬¦ $string = str_replace("\n", '', $string); //æ¸ é¤æ¢è¡ç¬¦ $string = str_replace("\t", '', $string); //æ¸ é¤å¶è¡¨ç¬¦ $pattern = array ("/> *([^ ]*) *</", "/[\s]+/", "/<!--[^!]*-->/", "/\" /", "/ \"/", "'/\*[^*]*\*/'"); $replace = array (">\\1<", " ", "", "\"", "\"", ""); $string = preg_replace($pattern, $replace, $string); foreach ((array)$matches[1] as $k => $v) { $string = str_replace("#{ $k}#", $v, $string); } return $string; } æ路就æ¯æåæ¿æ¢åº pre, code çåå 容. å¨å¤çå®ä¹å, åæ¿æ¢åæ¥. ps . å ¶å®é£ä¸ªå缩å½æ°æ²¡å¤å¤§ç¨é. nginx ç´æ¥å¼ gzip å缩就好äº. æçåæ§è½æ¯ç¨phpåè¦é«.