byokka
Last Updated: February 25, 2016
·
661
· barnettjw
43ea08b4fc547e8a5da87c207bea2123

Remove whitespace from CSS using PHP

Here's a great PHP script to minify CSS on-the-fly. However it removes all whitespace, that's a problem because it breaks some CSS.

So I fixed it...

This will strip whitespace from CSS, but leave syntactically significant whitespace for descendant selectors & shorthand properties.

$buffer = str_replace(array("\r\n", "\r", "\n", "\t"), '', $buffer);
$buffer = ereg_replace(" {2,}", ' ',$buffer);
Say Thanks
Respond