I had always wished CSS files weren’t so static so you could do different things at runtime. It turns out you can do it, but exercise common sense. The exact plan you take depends on how often the CSS “variables” change value. If it’s not too often you might want to “precompile” the style files into static and just use them the old style way.
Here is how you can use PHP to do ‘on-the-fly’ CSS files.
- Instead of including a static css file include a file with the php suffix as below:
<link rel='stylesheet' type='text/css' href='css/style.php' />
- Make sure your style.php file returns the appropriate headers for a text/css mime type as below:
header("Content-type: text/css; charset: UTF-8"); - Now set up variables in your style.php very much like you would for a view template:
$mainUrl = "http://dorkage.net"; $mainHeaderColor = "#FE0EDE";
- Refer to your variables using echo
#header { background: url("<?php echo $mainUrl; ?>/images/header-bg.png") no-repeat; } a { color: <?php echo $mainHeaderColor; ?>; }
CSS Tricks.com reported a different way to do this: This match rule in htaccess matches any file with style in it’s name and gets parsed as PHP thusly:
<FilesMatch "^.*?style.*?$"> SetHandler php5-script </FilesMatch>
They speculate that you wouldn’t be able to take advantage of the automatic cacheing that is normally provided for style files. However, you could precompile your style.php by running it through CLI php each time you update the “variables” thusly:
php style.php > style.css
and just include the resulting css file the normal way






Firebug is da bomb for debugging your web front end. Instead of just being able to look at the page source as it was delivered from the server, it lets you see the modified page after Javascript has run it through the ringer, it breaks things down heirarchically to help you focus, and it even lets you edit a page locally. 


I was investigating the CSV storage engine for mysql, having never used it. I found out, much to my relief, that it’s a relatively new thing — went standard with 5.1, but certainly not in the kits of luddites like me who have to stay four or five versions back because we can’t afford downtime caused by unexpected glitches with new releases. 