I want to minify HTML code using PHP && Regex code
The minify function :
public static function sanitize_output($buffer) {
$search = array(
'/ {2,}/',
'/<!--.*?-->|\t|(?:\r?\n[ \t]*)+/s'
);
$replace = array(
' ',
''
);
$buffer = preg_replace($search, $replace, $buffer);
return $buffer;
}
I use this function when I rendering the template (HTML file), but I get always this error on console
SyntaxError: missing } in compound statement note: { opened at line
The minify code delete some " { " on Js code, is there any solution the fix this problem?
After some search, I found that the error is in JS comments, when I minify the HTML code the comments concatenate with the code.
I try to use this regex
/\/\*[\s\S]*?\*\/|([^:]|^)\/\/.*$/
but it's doesn't work