iconicCreator Posted June 1, 2009 Share Posted June 1, 2009 With the help of the great people in here and some reading, I have managed to come up with a PHP script that displays random images every time a page loads or when user refreshes the page/browser. The script also echos a caption according to time of day. Now I would like to modified the script so that instead of the image changing every time the page/browser refreshes, it will display a different image everyday with a caption. So the script will display a different image everyday with a caption. Now my current script displays images on reload/refresh with caption. Here is the script. <?php $images = array( array('file' => 'image1a', 'caption' => 'Good [PARTOFDAY]! <br /> My name is Rick. <br /> Welcome to B&I.'), array('file' => 'image2a', 'caption' => 'Good [PARTOFDAY]! <br /> My name is Dianna. <br /> Welcome to B&I.'), array('file' => 'image3a', 'caption' => 'Good [PARTOFDAY]! <br /> My name is David. <br /> Welcome to B&I.'), array('file' => 'image4a', 'caption' => 'Good [PARTOFDAY]! <br /> My name is Mariah. <br /> Welcome to B&I.'), array('file' => 'image5a', 'caption' => 'Good [PARTOFDAY]! <br /> My name is Gabriel. <br /> Thanks for visiting B&I.'), array('file' => 'image6a', 'caption' => "Good [PARTOFDAY]! <br /> I'm Morrison. <br /> Thanks for visiting B&I.<br /> How can I help you?"), array('file' => 'image7a', 'caption' => "Good [PARTOFDAY]! <br /> I'm Chris. <br /> Thanks for visiting B&I.<br /> Do you have a question?"), array('file' => 'image8a', 'caption' => "Good [PARTOFDAY]! <br /> I'm Carlos. <br /> Welcome to B&I.<br /> How can I help you?"), ); $i = rand(0, count($images)-1); $selectedImage = "../my_website_images/{$images[$i]['file']}.jpg"; $caption = $images[$i]['caption']; function PARTOFDAY($string) { $hour = date("H",time()); if($hour >= 6 && $hour < 12) $replace = 'morning'; elseif($hour >= 12 && $hour < 18) $replace = 'afternoon'; elseif($hour >= 18 && $hour < 24) $replace = 'evening'; else $replace = 'morning'; return str_replace("[PARTOFDAY]",$replace,$string); } ?> Any ideas will be greatly appreciated. Thanks everyone! IC Quote Link to comment Share on other sites More sharing options...
ram4nd Posted June 1, 2009 Share Posted June 1, 2009 You have to give every image a day. And then compare the day with the day part of server time. Quote Link to comment 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.