Last active
October 7, 2015 02:07
-
-
Save erunion/3088095 to your computer and use it in GitHub Desktop.
PHP function to parse a blob of CSS and count up the total number of selectors present. Useful if you need/want to factor this into your test suite to make sure your CSS files never reach the 4095 limit in IE9 and lower.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Parse out a given string containing CSS and count up the total number of | |
* selectors that are present in it. | |
* | |
* @return integer | |
*/ | |
function countSelectors($css) { | |
$css = preg_replace('/\{(.*?)\}/s', '', $css); | |
$css = preg_replace('/[,]/', "\n", $css); | |
$selectors = explode("\n", $css); | |
$selectors = array_filter($selectors); | |
return count($selectors); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment