Really simple CSS compression function in PHP

Thanks to the simple syntax of CSS, we can easily compress the CSS code with a PHP function of only 3 lines of codes.

Since the compression will remove all the code indention and comments so it should be apply to production codes only.

Here is the CSS compression that I used in my projects.


function CSS_Compress(&$css){
    //new lines, multiple spaces/tabs/newlines
    $css = preg_replace('/[\r\n\t\s]+/s', ' ', $css);
    //remove comments
    $css = preg_replace('#/\*.*?\*/#', '', $css);
    //remove extra single spaces
    $css = preg_replace('/[\s]*([\{\},;:])[\s]*/', '\1', $css);
}