Minify CSS With PHP


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

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


Copy this code and paste it in your HTML
  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. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.