Re: IM A NOOB!
Posted: Tue Jun 24, 2008 11:37 pm
Have you ever programmed in PHP before?
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
file — Reads entire file into an array
A quick look at your requirements suggests the information will be stored locally on your site, and that it will be a straight text file with a new URL on each line. So the first thing I'd try is ...Return Values
Returns the file in an array. Each element of the array corresponds to a line in the file, with the newline still attached. Upon failure, file() returns FALSE.
Code: Select all
$lines = file('random_links.txt');
print_r($lines);Code: Select all
http://www.site1.com
http://www.site2.com
http://www.site2.comAll good so far. But that example on that page looks tricky. Let's read a bit more.array_rand — Pick one or more random entries out of an array
Return Values
If you are picking only one entry, array_rand() returns the key for a random entry. Otherwise, it returns an array of keys for the random entries. This is done so that you can pick random keys as well as values out of the array.
Hmmm ... seems easy enough. I dont need to call an array of values, just a single. And I shouldn't need call that srand() line with php5.Notes
Note: As of PHP 4.2.0, there is no need to seed the random number generator with srand() or mt_srand() as this is now done automatically.
Code: Select all
echo "My Random Site Is :- " . $lines[array_rand($lines)];