Re: HTML_CSS -> howto parse?

From: Date: Sat, 08 May 2004 18:04:39 +0000
Subject: Re: HTML_CSS -> howto parse?
References: 1 2 3 4  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-29037@lists.php.net to get a copy of this message
Florent Monnier wrote:
It is for my ImageMagick->Conjure class, as IM does not support CSS yet, I need to replace all class tags by the style tag with the css code to put each style included (and also add the css code for id tags but without removing it, or perhaps removing it since it is just a replacement in a buffer before giving it to ImageMagick in a blob).
Why not add a $css object to your class, using an instance of HTML_CSS... it provides full CSS support. Currently it has problems with inheritance, but I'm planning on fixing that next week. Give it a try.
So I am searching a Pear package to parse the CSS code into a PHP variable. Is there one? And even perhaps if it exists a class to parse the document and look for matching tags with the css code? (I don't think there is yet this, but have to ask to be sure.)
Try this: $css = new HTML_CSS(array()); // add whatever attribs you want. $css->parseString($string); // or // $css->parseFile($filename); There are a few quirks in parseString (which is also called by parseFile) due to the fact that all groups are moved to initial position, which can cause problems. As I mentioned before, I'm going to work on that this coming week. You can use the regular output options: toString() and display(). You can also define the mime an character encoding, etc. and access each selector individually (even retrieving values, etc.). Give it a spin :-) Klaus

« previous php.pear.dev (#29037) next »