Home » PHP

Generating random image

19 March 2008 119 views Popularity: 1% Share/Bookmark

email

Generating/Displaying random image in PHP.


<?php
/*********************************

RANDOM IMAGE GENERATION

<span id="more-45"></span>

*********************************/

//storing images in an array
$images = array(1 => "mukesh1.jpg", 2 => "mukesh2.jpg", 3 => "mukesh4.jpg", 4 => "mukesh6.jpg", 5 => "mukesh9.jpg");

//printing the array
/*** print_r($images); ***/

//generating random number
//we have 5 elements in the array above
//so we will generate random number from 1 to 5
$num = rand(1,5);

//printing the images
echo "Random Image Below: ";
echo "<br/>";
echo "<img src='".$images[$num]."' alt='Random Image' title='Random Image'>";

?>

Download code (images included):-

Random image in PHP

Enjoy PHPing !!

Related posts:

  1. PHP: Generating Multiple Random String
  2. Random number, string generation in PHP
  3. jQuery: Grey out background and preview image as popup
  4. Magento: Set Random Order in Collection using RAND()
  5. phpThumb(): The best PHP thumbnail image generator
  6. jQuery: Animate and Transfer effect with Image
  7. jQuery: Preview Image with Tooltip Effect
  8. jQuery: Preview Image with Zoom Effect
  9. Magento: Get height and width of Image
  10. Magento: Get width height of image using Varien_Image class