Possible Duplicate:
Parse a CSS file with PHP
I want to be able to search through a css file find the class or id and bring back its style.
IE.. css file layout
body {
margin:0;
padding:0;
}
span {
margin:0;
padding:0;
} #input { font:12px arial; }
a { color:#0000FF;
text-decoration:none;
}
.logout a:hover { text-decoration:underline; }
and i want to find say the id " #input " in the file and it to bring back the style so.
font:12px arial;
or #input{ font:12px arial; }
and ovioulsly if there is more bring that back to but to keep this small like.
i tried my self but no luck as im not so good in regular expressions.
if(file_exists("css/style.css") && filesize("css/style.css") > 0){
$filesize = filesize("css/style.css");
$handle = fopen("css/style.css", "r");
$contents = fread($handle, $filesize);
fclose($handle);
}
preg_match('@^(?:#input{)?([^}]+)@i', $contents, $matches);
echo "style: {$matches[0]} <br>";
print_r($matches2);
please help.