PHP压缩HTML/JS代码


PHP #压缩2012-04-30 09:08
以下代码可以压缩HTML和JS,但如果JS没有用分号结尾的会有问题。
$content = str_replace(array('','',"\r\n\r\n","\r\n","\n","   ","\t"),'',$content);

PHP str_replace() 函数 http://yige.org/php/func_string_str_replace.php

只压缩HTML不压缩JS

$content = preg_replace("~>\s+\r~", ">", preg_replace("~>\s+\n~", ">", $content));
$content = preg_replace("~>\s+<~", "><", $content);

相关文章

粤ICP备11097351号-1