I'm using code from this answer to minify HTML and then ob_gzhandler to gzip the page (because mode_deflate is disabled on my shared server and therefore I cannot gzip in .htaccess):
function sanitize_output($buffer) {
$buffer = preg_replace('/[\r\n]+\s*/', '', $buffer);
return $buffer;
}
ob_start("sanitize_output");
if(!ob_start("ob_gzhandler")) ob_start();
Both ob_start("sanitize_output") and ob_start("ob_gzhandler") work well on their own, but combining them causes a content encoding error:

What can I do?