Forum Moderators: coopster
Here's my code:
<?php
$url1="http://www.****1.com/";
$url2="http://www.****2.com/";
$url3="http://www.****3.com/";
$charset="0321";
$random=$charset[rand(0,4)+1];
$urlname="url".$random;
print $url;
?>
The trouble is when I print $url, it actually prints the variable name "url2" or whatever. I want it to print the variable's value, so instead of printing "url2" it would print $url2's value - [****2.com...]
How can I do this? Kind of urgent, so thanks loads for your help,
Cheers,
Jeremy
[edited by: ergophobe at 10:33 pm (utc) on Sep. 26, 2004]
[edit reason] delinked url [/edit]
Thanks loads for the answers and mod-edit, I tried that solution again but it doesn't work.
Here's my updated code:
<?php
$url1="http://www.****1.com/";
$url2="http://www.****2.com/";
$url3="http://www.****3.com/";
$charset="0321";
$random=$charset[rand(0,4)+1];
$urlname="url".$random;
print "$urlname";
?>
I want to generate a random url from a list of 3, so I create the $urlname string which is made of "url" + a random number giving me "url2", "url3" or whatever. However, I don't want this to be a string, I need it to be a variable's name. So when I print "url2", it doesn't say "url2" but prints the VALUE of the url2 variable, which would be "http://www.****2.com". Even with the quotation marks it's still just showing the text string "url2"
This seems to be a newbie question, all I want to do is print variable values rather than variable names. Thanks again for your help,
Jeremy