User Tools

Site Tools


Table of Contents


Now that we have a complete style sheet, we can run some utilities to help us along.

Note you can grab your own compressed and minified css off your site for this as well.


There are CSS parser and we should probably investigate. But this was fast and easy, I stole it from


//Grab contents of css file
$file = file_get_contents('./theme/frontend/mytheme/style/mytheme/css/auto.css');

//Strip out everything between { and }
$pattern_one = '/(?<=\{)(.*?)(?=\})/s';

//Match any and all selectors (and pseudos)
$pattern_two = '/[\.|#][\w]([:\w]+?)+/';

//Run the first regex pattern on the input
$stripped = preg_replace($pattern_one, '', $file);

//Variable to hold results
$selectors = array();

//Run the second regex pattern on $stripped input
$matches = preg_match_all($pattern_two, $stripped, $selectors);

$result = array_unique($selectors[0]);
//Show the results
echo '<pre>';
foreach($result as $i => $m)
    echo '<br>' . $m;
//echo '<pre>';


The output is shown here. Now we can use this with sed/awk to discover which are never used.


Somewhere I have a utility to extract colors from CSS. Find that and include it here.

It was with V2 utilities I think….

products/stewcss/util.txt · Last modified: 2015/01/10 08:51 by steward