简体   繁体   English

PHP中的CSS Minifier

[英]CSS Minifier in PHP

Do you know a small but effective class for minifying CSS files written in php that has no extra requirements? 你知道一个小而有效的类来缩小用php编写的CSS文件没有额外的要求吗? 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). 它应该用于优化用户生成的文件,并且必须支持CSS3,包括供应商特定的黑客和旧浏览器的后备(-moz-&-webkit-不被视为评论)。

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. CSSTidy - 它有一个PHP和C ++实现。

The following is a basic example how to use CSSTidy in PHP: 以下是如何在PHP中使用CSSTidy的基本示例:

<?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 . 我对minify有很好的经验。 You can rip out the CSS compressor class . 你可以淘汰CSS压缩器类 Should work with something like: 应该使用类似的东西:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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