Reply
PHP code for random url!
Old 05-02-2004, 05:13 PM PHP code for random url!
Junior Talker

Posts: 3
Im sure this is so easy but cant find in my book anywhere!

Just simply want to be able to add say 4 links to a text file ie http://mysite.com/url.php and then the script picks on of the 4 links randomly and loads it up? any got any tips for me?

Would be very greatful!
chris34 is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 05-02-2004, 05:31 PM
Christopher's Avatar
Iced Cap

Latest Blog Post:
PHP and Unicode with UTF-8
Posts: 3,108
Location: Toronto, Ontario
You can use file() to load the text file into an array, then use mt_rand() to choose a random one. Something like:

PHP Code:
$links file('myfile.txt');
$rand_link $linksmt_rand(0count($links) - 1) ];
echo 
'<a href="' $rand_link '">linkie!</a>'
Christopher is offline
Reply With Quote
View Public Profile Visit Christopher's homepage!
 
Reply     « Reply to PHP code for random url!
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.11914 seconds with 13 queries