I need some help creating a multi-dimensional array from CSS. For example:
$css = "body { font-weight:40px; color:#444; } #wrapper { width: 500px; }";
I do have the following code from Split CSS inside the {} to array of key/value pairs but this doesn't do the selector aswell
function BreakCSS($CSS) {
$results = array();
foreach(explode(';', $CSS) AS $attr)
if (strlen(trim($attr)) > 0) // for missing semicolon on last element, which is legal
{
list($name, $value) = explode(':', $attr);
$results[trim($name)] = trim($value);
}
return $results;
}
I am not a expert when it comes to this kind of coding. Ideally i would like:
array(
'body' => array (
array(
'font-weight',
'40',
'px'
),
array(
'color',
'#444',
''
)
)
)
Furthermore, is there a way of checking to see if !important has been added to the end?
Thanks in advance!