duangai2831 2018-08-29 19:32
浏览 24

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

How I can use this function to skip specified files and not minify them?

Minifier:

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

Text here. Text here.

  • 写回答

1条回答 默认 最新

  • dourui9570 2018-08-29 19:46
    关注
    // do not minify this file
    ob_flush();
    ob_end_clean();
    include($_SERVER['DOCUMENT_ROOT'].'/body.php');
    

    If you need minify next code -- call ob_start() manually before code block:

    <?php ob_start("sanitize_output"); ?>
    ...any html...
    
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么