Inline CSS modification using PHP
I am having HTML file with inline CSS available in tags. I want to change background-image, color, fonts etc. using PHP. Is there any option using which I can modify inline CSS easily using PHP? Please help me. Thanks in advance.
A bit of context is needed: why are you using inline styles to begin with, instead of an external stylesheet - or even an embedded stylesheet? Both would be easier to work with than generating a page with inline styles, then going back and altering the styles before serving the page.
Actually we are building website generator with different options like background color, background image, font color, font size etc. changing using wizard so we are generating runtime css for all & generating HTML out of it. So we need to edit this inline css at the time of publish.
Settled 4 red convertible
vBulletin's approach to this is interesting to me; of course, they've got a lotta brains putting their software together.
They use "stylevars" which live in the database, along with the associated properties. Their "css.php" file puts them all together according to its parameters, and is called in the HEAD of their HTML.
That might be too heavyweight for you ... but then again, I could see some benefits to using that or a similar approach in what you're talking about doing...
I'm still not seeing why the styles need to be inline. Even less so, now, since you're building the HTML as well, so you know what classes/ids the various elements will have (and of course the <body> element is going to be the <body> element). The whole point of stylesheets is that the stylesheet can be changed (to provide different backgrounds, fonts, etc.) without changing the HTML. The most compelling expression of this fact would be css Zen Garden.
Is it that you're generating the page every time, instead of once at publication time and storing the resulting files (during development you'd want the changes to be immediate even if it does mean more processing)? In that case inline styles still wouldn't be necessary; dalecosp describes one way an entire stylesheet can be embedded into the head of the document.
Finally: even if you are using inline styles when you build the HTML, it strikes me it would be less work putting the right styles in to begin with instead of wrong ones that subsequently have to be replaced.
However, if you have an HTML document you can load it into a DOM structure and get at the contents of all the various "style" attributes. Of course, you'll need to navigate the DOM to find the attributes you want, and the value of the attribute will be a string that you will still need to parse as a list of CSS declarations.
Last edited by Weedpacket; 04-05-2013 at 03:38 AM.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Tags for this Thread