01010111 01100001 01110100 01100011 01101000 00100000 01101111 01110101 01110100 00100000 01100110 01101111 01110010 00100000 01100010 01100101 01100001 01110010 01110011 00100000 01101111 01101110 00100000 01110100 01101000 01100101 00100000 01110011 01101100 01101111 01110000 01100101 01110011
July 25th, 2008
This is a neat little trick I sometimes use to freshen up websites that suffer from heavy text content The script will use an array of predefined images that exist in a directory and choose at random one of the images from within it.
// PHP Random Image Selecter
$arr_img_list = array('1.jpg','2.jpg','3.jpg','4.jpg','5.jpg','6.jpg','7.jpg','8.jpg','9.jpg');
$i_lower_limit = 0;
if(count($arr_img_list)>0){
$i_upper_limit = count($arr_img_list)-1;
}else{
$i_upper_limit = 0;
}
$i_random_no = mt_rand($i_lower_limit, $i_upper_limit);
$str_chosen_image = $arr_img_list[$i_random_no];
<img src=”/random/=$str_chosen_image;?>” class=”border” alt=”a random picture” />
Warning: The script as such simply displays the images in their natural format so its your responsibility to size them before dropping them in place. One good enhancement I will consider for the future would be to to add a thumbnail generating script to handle any size images.