Created
April 6, 2017 21:01
-
-
Save maximuspoder/bb815992816d1b64d3749fc7abc7cfc3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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