<?php
/**
* CSS compressor
* Copyright: 2007 New Digital Group, Inc.
* Author: Monte Ohrt (monte [at] ohrt [dot] com)
* License: LGPL
* Usage: $output = compress_css($string);
*/
function compress_css($buffer) {
// remove comments
$pattern = '!/\*[^*]*\*+([^/][^*]*\*+)*/!';
$buffer = preg_replace($pattern, '', $buffer);
// remove new lines, tabs, spaces
$buffer = str_replace(array(
"\r\n",
"\r",
"\n",
"\t",
' {',
'} ',
';}'
),
array(
'',
'',
'',
'',
'{',
'}',
'}'
)
, $buffer);
// drop more unecessary spaces
$buffer = preg_replace(array('!\s+!','!(\w+:)\s*([\w\s,#]
+;?)!'),array(' ','$1$2'),$buffer);
return $buffer;
}
?>