Random links Question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ampersand
Forum Commoner
Posts: 54
Joined: Thu Nov 28, 2002 2:00 am
Location: Norway

Random links Question

Post by ampersand »

How can I make random links from a text document ? so I just need to add links to this txt file and they appear random on a website.

Thanks in advance
Blackhat
[]InTeR[]
Forum Regular
Posts: 416
Joined: Thu Apr 24, 2003 6:51 am
Location: The Netherlands

Post by []InTeR[] »

Code: Select all

$links = file("links.txt");
echo $links[rand(0,sizeof($links)-1)];
Last edited by []InTeR[] on Wed Jun 11, 2003 7:42 am, edited 5 times in total.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

if you have one link per line in that file
take a look at http://php.net/file and http://php.net/array_rand

edit: @Inter: readfile adds the contents to the output stream and returns the size.
Post Reply