I'm looking for a PHP library(script) that will be able to combine CSS selectors with the same properties. Here is what I mean:
.myclass{
font-size: 14px;
color: red;
}
.something{
font-size: 14px;
color: red;
}
After processing the CSS above the result should be:
.myclass, .something{
font-size: 14px;
color: red;
}
Any help is appreciated.
A nice php library to do this is https://github.com/Cerdic/CSSTidy
Example code:
<?php
include('class.csstidy.php');
$css_code = '
.myclass{
font-size: 14px;
color: red;
}
.something{
font-size: 14px;
color: red;
}
';
$css = new csstidy();
$css->$css->set_cfg('merge_selectors', 2);
$css->parse($css_code);
echo $css->print->formatted();
?>
Output:
.myclass,.something {
font-size:14px; color:red
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With