Compress multi CSS with PHP


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php
  2.  
  3. header('Content-type: text/css');
  4.  
  5. ob_start("compress");
  6.  
  7. function compress($buffer) {
  8.  
  9. /* remove comments */
  10.  
  11. $buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);
  12.  
  13. /* remove tabs, spaces, newlines, etc. */
  14.  
  15. $buffer = str_replace(array("
  16. ", "\r", "\n", "\t", ' ', ' ', ' '), '', $buffer);
  17.  
  18. return $buffer;
  19.  
  20. }
  21.  
  22.  
  23.  
  24. /* your css files */
  25.  
  26. include('master.css');
  27.  
  28. include('typography.css');
  29.  
  30. include('grid.css');
  31.  
  32. include('print.css');
  33.  
  34. include('handheld.css');
  35.  
  36.  
  37.  
  38.  
  39. ?>

URL: http://reinholdweber.com/?p=37

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.