Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

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

Posts: 3
Trades: 0
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
 
 
Register now for full access!
Old 05-02-2004, 06:31 PM
Christopher's Avatar
Iced Cap

Latest Blog Post:
Cross-domain AJAX with JSONP
Posts: 3,110
Location: Toronto, Ontario
Trades: 0
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>'
__________________

Please login or register to view this content. Registration is FREE
- Latest Articles:
Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE

--
Please login or register to view this content. Registration is FREE

Christopher is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to PHP code for random url!
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB 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.26809 seconds with 12 queries