CSS Compressor

2 views
Skip to first unread message

Vasanth Govind

unread,
Sep 26, 2007, 4:38:24 AM9/26/07
to IntelliBitz Technologies, learne...@googlegroups.com
CSS Compressor
Link: http://phpinsider.com/compress_css.php

<?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;
}

?>

Reply all
Reply to author
Forward
0 new messages