Advertisement
CreativeJuiz

Minify CSS

Jan 10th, 2013
390
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.45 KB | None | 0 0
  1. <?php
  2. function minCSS( $string ) {
  3.  
  4.     /* Kill comments */
  5.     $string = preg_replace('!/\*.*?\*/!s','', $string);
  6.     $string = preg_replace('/\n\s*\n/',"\n", $string);
  7.  
  8.     /* Minification */
  9.     $string = preg_replace('/[\n\r \t]/',' ', $string);
  10.     $string = preg_replace('/ +/',' ', $string);
  11.     $string = preg_replace('/ ?([,:;{}]) ?/','$1',$string);
  12.  
  13.     /* Remove Trailing Semicolon */
  14.     $string = preg_replace('/;}/','}',$string);
  15.  
  16.     return $string;
  17. }
  18. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement