Skip to content

Instantly share code, notes, and snippets.

@maximuspoder
Created April 6, 2017 21:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maximuspoder/bb815992816d1b64d3749fc7abc7cfc3 to your computer and use it in GitHub Desktop.
Save maximuspoder/bb815992816d1b64d3749fc7abc7cfc3 to your computer and use it in GitHub Desktop.
<?php
function sanitize_output($buffer) {
$search = array(
'/\>[^\S ]+/s', // strip whitespaces after tags, except space
'/[^\S ]+\</s', // strip whitespaces before tags, except space
'/(\s)+/s', // shorten multiple whitespace sequences
'/<!--(.|\s)*?-->/' // Remove HTML comments
);
$replace = array(
'>',
'<',
'\\1',
''
);
$buffer = preg_replace($search, $replace, $buffer);
return $buffer;
}
ob_start("sanitize_output");
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment