MyBB Community Forums

Full Version: PHP Help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5
Okay, another PHP question, is
$something="something"
a string or variable? I am trying to make a random image generator for affiliates on my site, and a tutorial said "random string generator". Real simple right?
Thes a string the variable is just $something but all of it together is a string i believe
EZE Wrote:Okay, another PHP question, is
$something="something"
a string or variable?

It's a variable containing a string. As you know, all variables start with $, but they can store different properties. Like you can have
$x = 3
. $x is still a variable, but now it contains an integer. Smile
Okay, now, like your signature, how could I randomize between a few? The tutorials i found for random image generation all randomize from a folder, but some images are hot-linked, from imageshack.
$rand = rand(1, 5);

echo "<img src=\"somepath/tosome/image".$rand.".someext\" alt=\"\" />";

That should get you started
Yeah, but what if the images are hot-linked and are not named "image1" and stuff?
Then you'll need to create an array of them somehow. $image_array[$rand]
Could you give me a good link on how?
$rand = array('image1.gif',
'image2,gif',
'image3.gif',
'image4,gif',
'image5.gif',
'image6.gif' );

$variable= rand($rand);
PRINT ('<img src="http://www.yoururl.com/' . $variable . '">');

Not 100% sure if it will work or not. But I hope it helps you get started
It won't.
$variable = array('image1.gif',
                   'image2,gif',
                   'image3.gif',
                   'image4,gif',
                   'image5.gif',
                   'image6.gif' );

$rand= rand(0, count($variable));
echo '<img src="http://www.yoururl.com/' . $variable[$rand] . '">';
should work. Smile
Pages: 1 2 3 4 5