/ Published in: PHP
Set up and array of filenames, which correspond to the file names of the images you are trying to randomize.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php $bg = array('bg-01.jpg', 'bg-02.jpg', 'bg-03.jpg', 'bg-04.jpg', 'bg-05.jpg', 'bg-06.jpg', 'bg-07.jpg' ); // array of filenames $selectedBg = "$bg[$i]"; // set variable equal to which random filename was chosen ?> <style type="text/css"> <!-- body{ background: url(images/<?php echo $selectedBg; ?>) no-repeat; } --> </style>