Line 106 of cssparser.php
says:
list($codekey, $codevalue) = explode(":",$code);
The explode()
is generating the Undefined offset error. So that means that the css file getting parsed has in invalid statement somewhere and missing :
. The explode can't find any :
in $code
.
Now this is just an assumption (you didn't provide actual .css file), but the file might have some invalid content, something like this:
.classdefinition {
color #000000;
}
There's a :
missing between color
and #000000
.
I don't think a comment is the problem, as at first look, the class takes care of skipping them.
Try passing the css file through a CSS validator.
If the CSS syntax is OK, then the class has a bug.
Now if we both have the same (latest) version of cssparser.php
, a quick patch would be to replace lines 106-109 with:
$arr = explode(":", $code);
if (count($arr) == 2 && strlen(trim($arr[0])) > 0 && strlen(trim($arr[1])) > 0) {
$this->css[$key][trim($arr[0])] = trim($arr[1]);
}
But again, that doesn't guarantee invalid CSS will be parsed correctly and that this class is error free.
And mind that I didn't actually test or worked with the class, all that is suggested here is just by looking at the code you posted and the class code.
Later edit:
At a quick google search, I found PHP-CSS-Parser which looks more complete and robust, and it's hosted on Github (so others could contribute to it).
Another edit:
Also check this answer here, looks simple enough, but as the author says, doesn't handle comments inside selectors.
Hope this helped.