Jump to content

Using PHP to generate and write a CSS file?


random1

Recommended Posts

I currently am using a php file 'stylesheet.php' that echos out a validated CSS content for my site.

 

I want to write the CSS content to a file 'stylesheet-public.css'.

 

I've tried: http://php.net/manual/en/function.eval.php

 

but it does not work since the PHP content has multiple opening and closing tags (<?php ?>).

 

Any other ideas?

the file name must end in .PHP (unless you add a type to the php engine)

and the script needs to know its contents type..

So you should end up with something like this

<?php
header('content-type:text/css');
echo "/*CSS CODE*/";

Why are you going this route again?  Do you have a database that populates a CSS file?  That is the only reason I can think of for using PHP to create a CSS file.

 

If you really want to do this.. instead of eval I would look into the file editing functions like fwrite, fread, fget, etc

Opps I did it again!

Ignore my first post.. I completely missed the question! (got it around the wrong way)

 

however.. another quick dirty option is

<?php
file_put_contents("stylesheet-public.css",file_read_contents("http://yourDomain.com/yourCSS.php"));

 

Now you must read from the HTTP address, this will read the file from apache instead of direct, this will then parse the file for you, as if you was a client

 

But as Zanus said.. why ?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.