[^\S ]\s*|\s{2,})(?=(?:(?:[^<]++|<(?!/?(?:textarea|pre)\b))*+)(?:<(?>textarea|pre)\b|\z))%ix';
// regex to remove HTML comments
private static $STRIPCOMMENTREGEX = '~~';
// minifier callback
private static function callback($buffer) {
// remove all unneeded spaces in HTML and replace with space to prevent removing wanted spaces
$buffer = preg_replace(AstaHtmlMinifier::$STRIPHTMLREGEX, ' ', $buffer);
// Remove HTML comments and it's content
$buffer = preg_replace(AstaHtmlMinifier::$STRIPCOMMENTREGEX, '', $buffer);
return $buffer;
}
// buffer start filter function
public static function buffer_start() {
// call minifier callback
ob_start(array('AstaHtmlMinifier', 'callback'));
}
// buffer end filter function
public static function buffer_end() {
// check if buffer exists
if(ob_get_length()){
// flush buffer
ob_end_flush();
}
}
}
// init plugin - run constructor
new AstaHtmlMinifier();