Created
January 4, 2018 14:48
-
-
Save apertaoxis/f19c91bf8feb96edfd6bc425c7fa649d to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| 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