I want to be able to read a CSS file, and be able to extract all declarations of a given selector in to a string. For example, given the following stylesheet:
h1 {
font-size: 15px;
font-weight: bold;
font-style: italic;
font-family: Verdana, Arial, Helvetica, sans-serif;
}
div.item {
font-size: 12px;
border:1px solid #EEE;
}
I want to be able to call and get div.item, something like:
$css->getSelector('div.item');
Which should give me a string like:
font-size:12px;border:1px solid #EEE;
I have been looking around but can't find a parser that can do exactly that. Any ideas?
FYI: I need this to be able to convert selectors from a CSS and embed the styles dynamically in to HTML elements in email messages.
SOLUTION EDIT: I came up with my own crude solution and created a class to do what I was looking for. See my own answer below.