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  

Comments

RSS Icon Subscribe to comments
Posted By: JonyGreen on December 11, 2015

i find a free online css minifier service to compress your css code, so it will reduce the size of web page.

Posted By: JonyGreen on December 11, 2015

you can try this free online css compressor to reduce your css file size.

Posted By: JonyGreen on December 11, 2015

i find a free online css minifier service to compress your css code, so it will reduce the size of web page.

You need to login to post a comment.