php压缩前端代码,去除空行、空格
//压缩HTML
function compress_html($str ) {
$chunks = preg_split( '/(<pre.*?\/pre>)/ms', $str, -1, PREG_SPLIT_DELIM_CAPTURE );
$str = '';
foreach ( $chunks as $c )
{
if ( strpos( $c, '<pre' ) !== 0 )
{
$c = preg_replace( '/[\\n\\r\\t]+/', ' ', $c );
$c = preg_replace( '/\\s{2,}/', ' ', $c );
$c = preg_replace( '/>\\s</', '><', $c );
$c = preg_replace( '/\\/\\*.*?\\*\\//i', '', $c );
}
$str .= $c;
}
return $str;
}