dqiaw48488 2012-10-16 10:17 采纳率: 0%
浏览 66
已采纳

如何改进此代码以使用PHP组合/压缩CSS [关闭]

This is a popular snippet to compress multiple CSS with PHP.

 <?php
      header('Content-type: text/css');
      ob_start("compress");
      function compress($buffer) {
        /* remove comments */
        $buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);
        /* remove tabs, spaces, newlines, etc. */
        $buffer = str_replace(array("
    ", "", "
", "\t", '  ', '    ', '    '), '', $buffer);
        return $buffer;
      }

      /* your css files */
      include('master.css');
      include('typography.css');
      include('grid.css');
      include('print.css');
      include('handheld.css');

      ob_end_flush();
?>

Looking at the code, I can see that it will only compress the files, but will not combine them. How do I tweak it to combine the files too?

  • 写回答

1条回答 默认 最新

  • doutan8775 2012-10-16 10:21
    关注

    Have you tried the code? I'm pretty sure it combines it as well. It does the following: it sets a callback function to replace comments, tabs spaces and newlines. Then, it includes multiple CSS files (which all go through the same callback).

    In the end, the output is flushed to the browser. That would mean all CSS of all those files will be sent to the browser, which means it combines it as well.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求TYPCE母转母转接头24PIN线路板图
  • ¥100 国外网络搭建,有偿交流
  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型