1.å¦ä½ç¨phpå缩html代ç 并è¾åº
å¦ä½ç¨phpå缩html代ç 并è¾åº
å¦ä½ç¨phpå缩html代ç 并è¾åº
function compressHtml($string) { $matches = array(); preg_match_all('/(<(?输输出linux源码安装mongodb: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åè¦é«.
2024-11-23 12:30
2024-11-23 12:18
2024-11-23 11:53
2024-11-23 11:51
2024-11-23 10:54
2024-11-23 10:35
2024-11-23 10:25
2024-11-23 10:18