6 ## Get command line arguments.
7 $stylesheet = file_get_contents($argv[1]);
8 $stylesheet = preg_replace("/\\/\\*.+?\\*\\//", "", $stylesheet);
9 // $stylesheet = preg_replace("/\\s+/", " ", $stylesheet);
12 preg_replace_callback("/([^{}]+?){([^}{]+?)}/", 'AggregateStyles', $stylesheet);
13 function AggregateStyles($m) {
15 $selectors = explode(",", preg_replace("/,\\s+/", ",", trim($m[1])));
16 $styles = explode(";", preg_replace([ "/\\s+/", "/;\\s+/" ], [ " ", ";" ], rtrim(trim($m[2]), ";")));
17 $style_blocks[] = [ $selectors, $styles ];
21 // print_r($style_blocks);
23 foreach ($style_blocks as $block) {
24 foreach ($block[0] as $selector) {
25 foreach ($block[1] as $style) {
26 list($property, $value) = explode(": ", $style);
27 echo "$selector\t$property\t$value\n";