I want to make some changes to the way I use my CSS. I want to be able to use variables to define colours or something. So I could do the following
var red = '#FF0000';
And of course red would be replaced with ‘#FF0000’ where appropriate.
How can I do this? I sort of know how, I just don’t know the regular expressions or even if this is the best way to do it.
You can do this. Simply write your php into your .css files the way you would an HTML file, and then tell your webserver (probably apache) to parse that file with php.
You could add this to a .htaccess file in your css directory:
However, this is a bad technique as it will slow down the loading of your css files, and prevent end-user caching from making much of a speed difference. It can be a convenient shortcut for websites where you don’t care about performance, though.