Code Stuff |
If you want to insert a random image into a page but want to do it with a minimum amount of code, here is a very simple way to do it with both PHP and Javascript.
First name your images something like this:
text-1.jpg text-2.jpg text-3.jpg |
For PHP, just use a normal IMG tag where you want the image to display and insert the following code into it like so:
1 |
<img src="text-<?php echo rand(min,max); ?>.jpg"> |
For Javascript, use this code where you want the image:
1 |
<script type="text/javascript"> document.write("<IMG src='text-" + (Math.floor(Math.random() * (max - min + 1) + min) + ".jpg'>"); </script> |
In either case, replace min with number to start at and the max with the last number to include.