PHP text fileness

random image



<script language="JavaScript">

function random_imglink(){
var myimages=new Array()
//specify random images below. You can have as many as you wish
myimages[1]="r1.jpg"
myimages[2]="r2.jpg"
myimages[3]="r3.jpg"
myimages[4]="r4.jpg"
myimages[5]="r5.jpg"

var ry=Math.floor(Math.random()*myimages.length)
if (ry==0)
ry=1
document.write('<img src="'+myimages[ry]+'" border=0>')
}
random_imglink()
</script>


this is actually what i used, its almost the same though


<!--
imgArray = ["image.jpg", "image2.jpg", "image3.jpg"];
ranNum = Math.floor(Math.random()*imgArray.length);
document.write("<IMG SRC='"+imgArray[ranNum]+"' BORDER='0'>");
-->

nice code

much smaller:thumb:

ahmed:

i used this code

<?php 
$images[0] = 'randIMG1.jpg';
$images[1] = 'randIMG2.jpg';
$images[2] = 'randIMG3.jpg';
?>
<img src="<php? $rand = rand(0,2);
echo images[$rand];
?> "></img>

And it gave me this error:

Parse error: parse error, unexpected ‘[’, expecting ‘,’ or ‘;’ in /home/mdipi/public_html/php/random.php on line 14

<img src="<php? $rand = rand(0,2);

That is line 14. i dont see anything wrong though

it should be

<img src="<?php $rand = rand(0,2);
echo **$images[$rand];
?>"><
/img>

:blush:

lol thanks, its the little stuff that you over look eh?

hehe… i always do that :wink: