Random Image Generator In PHP
Posted: Sun Mar 26, 2006 10:09 pm
Random Image Generator In PHP
Here is a small and basic example of generating random images through PHP!
[PHP]//This line prevents a regular pattern of numbers to be generated.
Srand(microtime() * 1000000);
//This line creates a random integer between 1 and 3
$num = rand(1,3);
//Next we will use a switch statement to display the random image.
Switch($num)
{
case 1: $link=1; $img=images/img1.jpg; break;
case 2: $link=2; $img=images/img2.jpg; break;
case 3: $link=3; $img=images/img3.jpg; break;
}
//Now we will echo the dynamic content.
echo$link><img; [/PHP]
Here is a small and basic example of generating random images through PHP!
[PHP]//This line prevents a regular pattern of numbers to be generated.
Srand(microtime() * 1000000);
//This line creates a random integer between 1 and 3
$num = rand(1,3);
//Next we will use a switch statement to display the random image.
Switch($num)
{
case 1: $link=1; $img=images/img1.jpg; break;
case 2: $link=2; $img=images/img2.jpg; break;
case 3: $link=3; $img=images/img3.jpg; break;
}
//Now we will echo the dynamic content.
echo$link><img; [/PHP]