...

View Full Version : Css and PHP



Veni_Vidi_Vici
05-24-2011, 08:39 PM
Hello,

I am trying to have a random background image load each time I have my page load. To do so, I tried the following:



<?php
$backs[0] = "background1.gif";
$backs[1] = "background2.gif";
$backs[2] = "background3.gif";
$randBackNum = rand(0,2);
?>

body { background: url($backs[$randBackNum]) 50% 50% no-repeat fixed; }


Except that it seems I can't call the php variable from the css statement because I'm outside the PHP tags. However, if I try to stick the css statement into the PHP tags I naturally get an error as it's trying to interpret that statement as php code....

As you may have assumed I do not know much about this subject matter; css and php are new to me, I only know basic html, so I would appreciate any help that can be provided. I hope that what I am asking for is simple enough. Thanks!

-Veni

P.S. The css formatting is correct for what I want to do when I hard code in an image file.

tangoforce
05-24-2011, 08:43 PM
body { background: url(<?php print $backs[$randBackNum]; ?>) 50% 50% no-repeat fixed; }



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum