was screwing around with the idea, here's what I came up with
Code: Select all
<?php
$file = "body
{
color:#111;
display:inline;
filter: progid:DXImageTransform.Microsoft.filtername(sProperties);
}
body2{color:#000;display:inline;filter: progid:DXImageTransform.Microsoft.filtername(sProperties);}
body3{
color:#222;
display:inline;
filter: progid:DXImageTransform.Microsoft.filtername(sProperties);
}
/*
remove the comments
*/
body .super #idnum {
color:
#333;
display:
inline;
filter: progid:DXImageTransform.Microsoft.Alpha(opacity:50);
}";
// remove comments
$file = preg_replace("|\s*/\*.*?\*/\s*|s","",$file);
// remove not needed spaces
$file = preg_replace("|\s*([\{\}:;])\s*|","\\1",$file);
//echo '<pre>'.print_r($file,true).'</pre>';
// tear the blocks apart
$clean = preg_split("|\s*?[{}]\s*?|",$file,-1,PREG_SPLIT_NO_EMPTY);
//echo '<pre>'.print_r($clean,true).'</pre>';
$x = 0;
$last = "";
foreach($clean as $piece)
{
if($x % 2 == 0)
{
$tag = $piece;
}
else
{
$tags[$tag] = array();
$piece = preg_split("|\s*?;\s*?|",$piece,-1,PREG_SPLIT_NO_EMPTY);
foreach($piece as $part)
{
$part = preg_split("|\s*?:\s*?|",$part,2,PREG_SPLIT_NO_EMPTY);
$tags[$tag][$part[0]] = $part[1];
}
}
$x++;
}
// spit it out
echo '<pre>'.print_r($tags,true).'</pre>';
}
?>
outputs
Code: Select all
Array
(
їbody] => Array
(
їcolor] => #111
їdisplay] => inline
їfilter] => progid:DXImageTransform.Microsoft.filtername(sProperties)
)
їbody2] => Array
(
їcolor] => #000
їdisplay] => inline
їfilter] => progid:DXImageTransform.Microsoft.filtername(sProperties)
)
їbody3] => Array
(
їcolor] => #222
їdisplay] => inline
їfilter] => progid:DXImageTransform.Microsoft.filtername(sProperties)
)
їbody .super #idnum] => Array
(
їcolor] => #333
їdisplay] => inline
їfilter] => progid:DXImageTransform.Microsoft.Alpha(opacity:50)
)
)
course, this won't take care of shared definitions.... sorta.
[edit] thinking about it, when showing the tag names, you could split on the comma (with trailing and leading spaces, probably)..