Skip to content

Instantly share code, notes, and snippets.

@apertaoxis
Created January 4, 2018 14:48
Show Gist options
  • Select an option

  • Save apertaoxis/f19c91bf8feb96edfd6bc425c7fa649d to your computer and use it in GitHub Desktop.

Select an option

Save apertaoxis/f19c91bf8feb96edfd6bc425c7fa649d to your computer and use it in GitHub Desktop.
<?php
if (!function_exists('remove_html_comments')){
/**
* @param string $content (html)
* @return string
*/
function remove_html_comments($content = null)
{
$result = preg_replace('/<!--(.|\s)*?-->/', '', $content);
return $result;
}
}
if (!function_exists('sanitize_output')) {
/**
* @param string $buffer (html)
* @return string
*/
function sanitize_output($buffer = null)
{
$search = ['/\>[^\S ]+/s', '/[^\S ]+\</s', '/(\s)+/s']; // Strip whitespaces after and before tags, except space and shorten multiple whitespace sequences
$replace = ['>', '<', '\\1'];
$result = preg_replace($search, $replace, $buffer);
$result = remove_html_comments($result); // Remove HTML Comments
return $result;
}
}
ob_start("sanitize_output");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment