Posted By

kendsnyder on 01/18/11


Tagged

css minify


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

ColdKeyboard


Minify CSS


 / Published in: PHP
 

  1. function compressCss($css) {
  2. $css = preg_replace('~/\*.*?\*/~s','',$css); // comments
  3. $css = str_replace(array("\n","\t","\r"),'',$css); // newlines and tabs
  4. $css = preg_replace('/: */',':',$css); // space after colons
  5. $css = preg_replace('/ *(;|\{|\}) */','$1',$css); // space before/after semicolons and braces
  6. $css = str_replace(';}','}',$css); // remove final semicolon
  7. $css = trim($css);
  8. return $css;
  9. }

Report this snippet  

You need to login to post a comment.