[thelist] Using PHP to write CSS

Peter Johansson peter at johansson.org
Tue May 21 05:04:00 CDT 2002


On Mon, 20 May 2002, Andy Warwick wrote:

> If you are on Apache server you can add the following line to your .htaccess
> file and PHP will directly parse your CSS files as well; there will be a
> performance hit, but I suspect it will be less than loading a file into a
> variable then writing it back.
>
>     AddHandler application/x-httpd-php .css
>
> That way you can simply transfer your PHP code into the included stylesheet and
> parse it in situ.

There's also always the option to just @import a php-file which outputs
information. Like so:

<style type="text/css" media="screen">
@import "style.php";
</style>

And then in style.php you let php output appropriate css. That way you
don't have to tamper with the server config.

Very similar approach, but you keep you php-code in files with suffix
.php (which is somewhat neater imho).

Regards,
Peter




More information about the thelist mailing list