如何改进此代码以使用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?

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.