简体   繁体   中英

CSS Minifier in PHP

Do you know a small but effective class for minifying CSS files written in php that has no extra requirements? It shall serve to optimize user generated files and has to support CSS3 including the vendor specific hacks and fallbacks for older browser (-moz- & -webkit- not being seen as comments).

I have searched for this topic a little bit but it seems like most solutions here are more or less outdated :(

CSSTidy - It has a PHP and C++ implementation.

The following is a basic example how to use CSSTidy in PHP:

<?php
include('class.csstidy.php');

$css_code = '
a {
  color:black;
  background-color:blue;
}';

$css = new csstidy();

$css->set_cfg('remove_last_;',TRUE);

$css->parse($css_code);

echo $css->print->formatted();

?>

I've had good experience with minify . You can rip out the CSS compressor class . Should work with something like:

$minified = Minify_CSS_Compressor::process($css);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM