如何使用PHP仅缩小指定的文件/页面的一部分



如何使用此功能跳过指定的文件而不缩小它们?

缩小器:

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');

文本在这里。文本在这里。

// 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...

最新更新