Re: HTML_CSS -> howto parse?

From: Date: Mon, 10 May 2004 18:48:21 +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-29058@lists.php.net to get a copy of this message
Florent Monnier wrote:
hi, It seems you did not understood my problem, or I did not explain well since I am not very good in ingleesh :) (Or perhaps I did not understood your answer too;) I don't want to create CSS code, I want to read CSS code. What I have to do is to get in a var, the CSS code that is in the head of the document, then remove it (or it will produce an error), and then to put each css code block in each tag of the document in theirs 'style' attribute. I had a quick look at HTML_CSS and it seems it is only designed to create CSS code and not to read it yet. Am I wrong? Here is an exemple, I have to transform the code of the file "what_I_have.svg" to a string "$what_I_want" before to feed IM with it. Cheers
It reads CSS just fine. Use parseString to read it into an array and then you can use getStyle. Try the following code. It does not work for groups yet. That's a limitation that I'm working on fixing. <?php require_once 'HTML/CSS.php'; $css = new HTML_CSS(); $css->parseString($stylesheet); // here you set whatever still needs to be set $css->setStyle('body', 'background-color', '#0c0c0c'); $css->setStyle('body', 'color', '#ffffff'); $css->setStyle('h1', 'text-align', 'center'); $css->setStyle('h1', 'font', '16pt helvetica, arial, sans-serif'); $css->setStyle('p', 'font', '12pt helvetica, arial, sans-serif'); // here you can force body to be the same style as p $css->setSameStyle('body', 'p'); echo '<body style="' . $css->toInline('body') . '">'; // will output: // <body style="font:12pt helvetica, arial, sans-serif;background-color:#0c0c0c;color:#ffffff;"> ?>

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