PHP in CSS file - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: PHP in CSS file (/showthread.php?tid=9226) |
PHP in CSS file - El Forum - 06-17-2008 [eluser]Kemik[/eluser] Hey all, This is a bit of a noob question but if I put php in a css file and load the css file as normal will the php run? Code: #middle_banner{ PHP's rand() function would be great to select a random middle_banner. I was going to do middle_banner_<?php rand(2, 6) ?>.jpg Thanks. PHP in CSS file - El Forum - 06-17-2008 [eluser]daulex[/eluser] found this on the net Quote:I guess php tags were not being processed because the webserver did not associate a .css file with the php script engine. PHP in CSS file - El Forum - 06-17-2008 [eluser]Tom Glover[/eluser] [quote author="daulex" date="1213747249"]found this on the net Quote:I guess php tags were not being processed because the webserver did not associate a .css file with the php script engine.[/quote] Remember php ignores any other code in a file that is not wrapped in php tags. PHP in CSS file - El Forum - 06-17-2008 [eluser]Kemik[/eluser] I tried changing the extension to php before I opened this topic as it seemed common sence. Apparently you need to add some header and content type info to the top of the css file, which I originally missed. PHP in CSS file - El Forum - 06-17-2008 [eluser]Wilbur Himself[/eluser] you can do it, you must have the file with a .php extension, and you must set a header like: header('Content-type: text/css'); PHP in CSS file - El Forum - 06-17-2008 [eluser]John_Betong[/eluser] Hi Kemik, >>> PHP’s rand() function would be great to select a random middle_banner. >>> I was going to do middle_banner_<?php rand(2, 6) ?>.jpg I recently introduced this code so that the 1676x76px smiley banner starts at a different position each time the page is loaded. Code: <body> You can see it here |