note 23810 deleted from ref.array by sniper
| From: | sniper@php.net | Date: | Sat, 18 Oct 2003 18:04:08 +0000 |
| Subject: | note 23810 deleted from ref.array by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-58843@lists.php.net to get a copy of this message | ||
Note Submitter: michael@ettl.co.at
----
CSS-Parsing Function with associative array and PREG - splitting.
You can fetch CSS-Tags with
$aCSS=parseCSS("style.css");
echo $aCSS["body"]["background-color"];
function parseCSS($filename)
{
$fp=fopen($filename,"r");
$css = fread($fp, filesize ($filename));
fclose($fp);
$css=preg_replace("/[\s,]+/","",$css);
$css_class = preg_split("/}/", $css);
while (list($key,$val) = each ($css_class))
{
$aCSSObj=preg_split("/{/",$val);
$a=preg_split("/;/",$aCSSObj[1]);
while(list($key,$val0) = each ($a))
{
if($val0 !='')
{
$aCSSSub=preg_split("/:/",$val0);
$aCSSItem[$aCSSSub[0]]=$aCSSSub[1];
}
}
$aCSS[$aCSSObj[0]]=$aCSSItem;
unset($aCSSItem);
}
unset($css);
unset($css_class);
unset($aCSSSub);
unset($aCSSItem);
unset($aCSSObj);
return $aCSS;
}