Combining css selectors with the same properties, php

I am looking for a PHP library (script) that can combine a CSS selector 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.

+5
source share
2 answers

Good php library for this - https://github.com/Cerdic/CSSTidy

Code example:

 <?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 } 
+7
source
0
source

Source: https://habr.com/ru/post/1244959/


All Articles