random1 Posted January 12, 2010 Share Posted January 12, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/188198-using-php-to-generate-and-write-a-css-file/ Share on other sites More sharing options...
MadTechie Posted January 12, 2010 Share Posted January 12, 2010 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*/"; Quote Link to comment https://forums.phpfreaks.com/topic/188198-using-php-to-generate-and-write-a-css-file/#findComment-993556 Share on other sites More sharing options...
Zane Posted January 12, 2010 Share Posted January 12, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/188198-using-php-to-generate-and-write-a-css-file/#findComment-993560 Share on other sites More sharing options...
MadTechie Posted January 12, 2010 Share Posted January 12, 2010 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 ? Quote Link to comment https://forums.phpfreaks.com/topic/188198-using-php-to-generate-and-write-a-css-file/#findComment-993565 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.