Posted By

thefricky on 05/16/11


Tagged

css php minify


Versions (?)

Minify CSS With PHP


 / Published in: PHP
 

URL: http://kitmacallister.com/2011/minify-css-with-php/

As simple as it can be. An PHP minifier. All the credits go to his author, Kit MacAllister

  1. /* Minify CSS */
  2. function minifyCSS($string){
  3.  
  4. /* Strips Comments */
  5. $string = preg_replace('!/\*.*?\*/!s','', $string);
  6. $string = preg_replace('/\n\s*\n/',"\n", $string);
  7.  
  8. /* Minifies */
  9. $string = preg_replace('/[\n\r \t]/',' ', $string);
  10. $string = preg_replace('/ +/',' ', $string);
  11. $string = preg_replace('/ ?([,:;{}]) ?/','$1',$string);
  12. return $string;
  13. }

Report this snippet  

You need to login to post a comment.