Simple variable problem with file name.


The problem is this. I generate a file name using a random number generator and this works find. Using echo the name of the file comes up just fine. But when I attempt to use that to call an image all I get is a blank image space.

The code is as follows


function getdice()
$random = (rand()%6);
if ($random==0) $random=1;
return $random;

$imagestring= “die-” . getdice();
$newstring=$imagestring . “.gif”;

echo $newstring;



The variable newstring is the file name. and if you go to the page you will see the file name is just fine. But the image does not come up. The images are in the same directory as the php page.

Thanks for help with this


I found the solution…that w3 school gets me into all kinds of trouble. After searching around the net the answer is to change the following:

<img src="<?php $newstring;?>" width="32" height="32" alt="X">


<img src="<? echo $newstring?>" width="32" height="32" alt="X">

This works!