(My apologies if this has been asked before; trying a search turns up tons of irrelevant stuff, as PHP and CSS are often mentioned together.)
I'm customizing a template (from OSWD), and it's using CSS to set an image. I have a series of 31 images that I want to use there, so I thought I'd simply move it out of the CSS and into the HTML, and use PHP to randomly pick one. It turns out that this is easier said than done.
Is there a way (preferably not serverwide) to make PHP parse CSS files? I thought there was an easy way to do it with .htaccess, but I can't seem to find how anymore.
(The alternative is to whip up a qiuck script to spit out 31 CSS files, differing only in the image they load, and have the pages use PHP to load the appropriate CSS file. This strikes me as a good way to cause problems later down the road, though.)
I've done sort of the opposite for years now; on various sites I've used a PHP script as the stylesheet, with 'header("Content-Type: text/css");' to send the correct MIME-type and have browsers apply it as CSS.
That way you can have all the PHP logic you want in the stylesheet, and not have to worry about causing non-PHP-based stylesheets to be parsed by PHP.
If you still prefer to have a .css file parsed by PHP, though, you can use ForceType directive in Apache to do it; if your stylesheet is called 'styles.css', for example, this would work: