PHP Code In CSS?
How do I get PHP code to be executed within my CSS files _AND_ have it work when the page hass XHTML Transitional or XHTML Strict DocTypes?
Right now I set my stylesheets to be a php file (styles.php) and I have my page's DocType as XHTML Strict. It works fine in IE 6 and Opera 7.5 but it fails in FireFox (no styles are shown). Same thing happens if I change the page to XHTML Transitional. When I remove the DocType, however, it works fine. Any ideas?
I've also tried adding the following to my .htacess file but this also fails (the php codes doesn't get executed).
And to mods: I posted this in the CSS forum because this really has more to do with CSS than PHP.
AddType application/x-httpd-php .css
If you want .css files to be processed for php before being sent to the browser, you'll have to tell apache to do so (I'm assuming you're using apache.) Depending on your server setup, you may be able to do this through your .htaccess file by adding (or editing if it already exists, this line:
AddType application/x-httpd-php .php .php3 .phtml .html .css
This tells apache what files to process for php code.
EDIT: You might want to leave the .html out of the line above if you don't need html files processed as PHP. Sending .html file through the PHP processor will slightly slow down the speed in speed in serving html files.
I think you also need to include this line at the top of the css.
More info here:
<?php Header ("Content-type: text/css");?>
Hope that helps.