Javascript 需要正则表达式来压缩html,但不包括pre、textarea和脚本标记PHP

Javascript 需要正则表达式来压缩html,但不包括pre、textarea和脚本标记PHP,javascript,php,html,regex,compression,Javascript,Php,Html,Regex,Compression,我测试了几个小型正则表达式来压缩html,它们基本上都做得很好 $reg = array( '/^\n+|^[\t\s]*\n+/m', '/\s\s+/', '/\r|\n/isU', '/\t/isU' ); $rep = array( '', ' ', ' ', ' ' ); ---------------------- $reg = array( '/\n/', // replace end of l

我测试了几个小型正则表达式来压缩html,它们基本上都做得很好

$reg = array(
    '/^\n+|^[\t\s]*\n+/m',
    '/\s\s+/',
    '/\r|\n/isU',
    '/\t/isU'
);
$rep = array(
    '',
    ' ',
    ' ',
    ' '
);
----------------------
$reg = array(
    '/\n/',         // replace end of line by a space
    '/\>[^\S ]+/s',     // strip whitespaces after tags, except space
    '/[^\S ]+\</s',     // strip whitespaces before tags, except space
    '/(\s)+/s'      // shorten multiple whitespace sequences
);
$rep = array(
' ',
'>',
'<',
'\\1'
);
------------------------------
$reg ='/\s\s+/';
$rep =" ";
----------------------
$reg = "/(\n\r|\r\n|\n|\r|\t| {2})/";
$rep ="";

$new_content = preg_replace($reg, $rep, $content);
$reg=array(
“/^\n+| ^[\t\s]*\n+/m”,
'/\s\s+/',
“/\r |\n/isU”,
“/\t/isU”
);
$rep=数组(
'',
' ',
' ',
' '
);
----------------------
$reg=数组(
“//\n/”,//用空格替换行尾
'/\>[^\S]+/S',//除去标记后的空格,空格除外
“/[^\S]+\”,

'为什么要使用正则表达式而不是HTML解析器?让服务器来做(gzip)