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
Filed Under
Did you know?
PHP applications still send a browser full of JavaScript. Hardening the server does not inventory the payment, analytics, and plugin scripts that run after the HTML is delivered.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#