Compress & minify CSS with php


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

Use always


Copy this code and paste it in your HTML
  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('style.css');
  15. # include('print.css');
  16. # include('handheld.css');
  17.  
  18. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.