In a recent project, the main CSS file actually reached 9800 lines, and I was shocked.
So I wrote a PHP code that combines the same CSS.
After merging, there are a few small issues. I have a hard time looking for any issues. Just change the CSS to OK. There is a compression function, which is enabled by default, but I did not try it.
<? Phpdefine ('cmp ', $ argv> 1? $ Argv [1]: True); // compress if (CMP) {define ('pa', ''); define ('tab ',''); define ('nl ', '');} else {define ('pa',''); define ('nl', "\ n ");} define ('tab ', "\ t"); $ STR = file_get_contents('green1.css'); $ STR = preg_replace ('/\/\*. * \ // ', '', $ Str); $ STR = preg_replace ('/\/\/. */', '', $ Str ); /* echo '============================= '. $ Str. '=========================== '; */preg_match_all ("/([^ {] +) \ {([^}] +)}/", $ STR, $ out); $ arr = array (); echo 'there are :'. count ($ out [0]). 'css classe '. CHR (10); For ($ I = 0; $ I <count ($ out [1]); $ I ++) {$ out [1] [$ I] = trim ($ out [1] [$ I]); $ left = substr ($ out [1] [$ I], 0, 1); if ($ left = '. ') {$ left = 'dot'; $ right = substr ($ out [1] [$ I], 1);} else if ($ left = '#') {$ left = 'jin'; $ right = substr ($ out [1] [$ I], 1);} else {$ left = 'emp '; $ right = $ out [1] [$ I];} $ CLS = $ left. $ right; if (isset ($ arr [$ CLS]) $ arr [$ CLS] = array (); $ stys = explode (';', $ out [2] [$ I]); For ($ J = 0; $ j <count ($ stys); $ J ++) {$ TMP = explode (': ', $ stys [$ J]); If (count ($ TMP) = 2) {$ arr [$ CLS] [trim ($ TMP [0])] = trim ($ TMP [1]);} else if (strlen (TRIM ($ stys [$ J])> 0) {echo 'error :'. $ stys [$ J]. CHR (10) ;}}$ STR = ''; foreach ($ arr as $ CLS =>$ v) {$ pre = substr ($ CLs ); $ left = substr ($ CLs, 3); if ($ pre = 'dot ') {$ CLS = '. '. $ left;} else if ($ pre = 'jin') {$ CLS = '#'. $ left;} else if ($ pre = 'emp') {$ CLS = leleft?file_put_contents('green.css ', $ Cls. '{'. NL, file_append); foreach ($ V as $ sty => $ txt?file_put_contents('green.css ', Tab. $ sty. ':'. spa. $ TXT. ";". NL, file_append1_1_file_put_contents('green.css ','}'. "\ r \ n", file_append );}