Posted By

nshakin on 11/02/12


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

o0110o


CSS Combine and Compress


 / Published in: PHP
 

URL: http://www.catswhocode.com/blog/3-ways-to-compress-css-files-using-php

Combine multiple css files into 1 file that has been stripped of whitespace and comments.

  1. <?php
  2. header('Content-type: text/css');
  3. ob_start("compress");
  4. function compress($buffer) {
  5. /* remove comments */
  6. $buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);
  7. /* remove tabs, spaces, newlines, etc. */
  8. $buffer = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', $buffer);
  9. return $buffer;
  10. }
  11.  
  12. /* your css files */
  13. include('master.css');
  14. include('typography.css');
  15. include('grid.css');
  16. include('print.css');
  17. include('handheld.css');
  18.  
  19. ?>

Report this snippet  

You need to login to post a comment.