如何在不删除IE条件注释的情况下缩小php html输出?
我使用以下PHP脚本缩小HTML页面:如何在不删除IE条件注释的情况下缩小php html输出?,php,Php,我使用以下PHP脚本缩小HTML页面: function compress_html($html) { preg_match_all('!(<(?:code|pre|script).*>[^<]+</(?:code|pre|script)>)!', $html, $pre); $html = preg_replace('!<(?:code|pre).*>[^<]+</(?:code|pre)>!', '#pre#', $
function compress_html($html)
{
preg_match_all('!(<(?:code|pre|script).*>[^<]+</(?:code|pre|script)>)!', $html, $pre);
$html = preg_replace('!<(?:code|pre).*>[^<]+</(?:code|pre)>!', '#pre#', $html);
$html = preg_replace('#<!–[^\[].+–>#', '', $html);
$html = preg_replace('/[\r\n\t]+/', ' ', $html);
$html = preg_replace('/>[\s]+</', '><', $html);
$html = preg_replace('/\s+/', ' ', $html);
if (!empty($pre[0])) {
foreach ($pre[0] as $tag) {
$html = preg_replace('!#pre#!', $tag, $html,1);
}
}
return $html;
}
ob_start('compress_html');
函数压缩\u html($html)
{
preg_match_all('!([^您的代码不处理多行HTML注释,只删除第一行。此外,如果您/您的服务器使用gzip压缩,您从中获得的节省可以忽略不计。例如:
未压缩、未缩小的页面:2209字节
压缩的未缩小页面:959字节
未压缩、缩小的页面:1973字节
压缩、缩小页面:914字节
最后两点:
缩小HTML使其几乎无法阅读,因此祝您好运
较大的页面通常具有更好的压缩比,尤其是在数据重复的情况下
所以去掉那一行。也去掉这一行:$html=preg_replace(“##,”$html);