缩小器:
function sanitize_output($buffer) {
$search = array(
'/\>[^\S ]+/s',
'/[^\S ]+\</s',
'/(\s)+/s',
'/<!--(.|\s)*?-->/'
);
$replace = array(
'>',
'<',
'\\1',
''
);
$buffer = preg_replace($search, $replace, $buffer);
return $buffer;
}
ob_start("sanitize_output");
HTML:
// this file contains above minifier
include($_SERVER['DOCUMENT_ROOT'].'/include-minifier.php');
// should be minified
<p style='display: block'>custom text</p>
// do not minify this file
include($_SERVER['DOCUMENT_ROOT'].'/body.php');
在此处输入文字。在此处输入文字。
答案 0 :(得分:0)
// do not minify this file
ob_flush();
ob_end_clean();
include($_SERVER['DOCUMENT_ROOT'].'/body.php');
如果您需要精简下一个代码,请在代码块之前手动调用ob_start()
:
<?php ob_start("sanitize_output"); ?>
...any html...