IF you are using a stylish and feature rich environment for your website, then your CSS files must have reached its limit of annoyance for you. So how can you compress CSS files using PHP? You can. Here is a simple trick to do that. On top of it all when you do it for an existing process, all the older files have to be renamed (CSS files to .php) and thus taking another handful of time and space increasing both the complexities. Keeping that in mind this code won't ask you to rename the files even. Don't you wanna know?

Code

< ?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("\r\n", "\r", "\n", "\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();
? >

Thanks to him for sharing the code with us.

[p.s. - Ignore the space between < ? and ? > in the original program]