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);
Written by James Barnett
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#