TimYang.com ::: The Geek Blog

Thursday December 09

Random image link

A javascript that inserts a random image with its corresponding link. I need this for a website project I'm doing. But I'm keeping my eye out for a PHP script that does this because javascript tends to take a bit longer to load.



Will this do ya?

$images = array(

$urls = array(

$image = rand(0, sizeof($images)-1);

echo “<a href=’{$urls[$image]}’><img src=’http://richardathome.no-ip.com/img/{$images[$image]}’ alt=’{$urls[$image]}’/></a>”;

Don’t forget to chage the location of your image directory :-)

working example here: http://richardathome.no-ip.com/examples/random_image_link/

Posted by: Richard@Home on Dec 09, 04 | 7:43 pm

Thanks Richard!

I’ll try it out tonight! I’m at an internet cafe now. I’m going around (or at least I was going to until it started raining) to see some buddhist temples with a Spanish friend.

Posted by: Tim on Dec 11, 04 | 6:10 pm
Leave a Comment

Tim Yang © // Email Me // XHTML 1.1 // CSS valid // 508 Passed // My PDF resume