note 23810 added to ref.array
| From: | michael at ettl dot co dot at | Date: | Mon, 29 Jul 2002 10:31:15 +0000 |
| Subject: | note 23810 added to ref.array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-33865@lists.php.net to get a copy of this message | ||
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;
}
--
http://www.php.net/manual/en/ref.array.php
http://master.php.net/manage/user-notes.php?action=edit+23810
http://master.php.net/manage/user-notes.php?action=delete+23810
http://master.php.net/manage/user-notes.php?action=reject+23810