Posted By

localhorst on 02/28/09


Tagged

css compress


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

luman
jitendraweb
nkrstevski
vali29


compress CSS files using PHP


 / Published in: PHP
 

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

  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("
  9. ", "\r", "\n", "\t", ' ', ' ', ' '), '', $buffer);
  10. return $buffer;
  11. }
  12.  
  13. /* your css files */
  14. include('master.css');
  15. include('typography.css');
  16. include('grid.css');
  17. include('print.css');
  18. include('handheld.css');
  19.  
  20. ?>

Report this snippet  

You need to login to post a comment.