note 71953 deleted from function.ob-start by cmb
| From: | cmb@php.net | Date: | Sun, 05 Jan 2020 08:14:38 +0000 |
| Subject: | note 71953 deleted from function.ob-start by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-213744@lists.php.net to get a copy of this message | ||
Note Submitter: Tobias Goldkamp
----
I use this to strip unnecessary characters from HTML output:
<?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
);
$replace = array(
'>',
'<',
'\\1'
);
$buffer = preg_replace($search, $replace, $buffer);
return $buffer;
}
ob_start("sanitize_output");
?>