help me code a simple script

sussah

Newbie
Joined
Dec 1, 2011
Messages
37
Reaction score
2
i want to write pretty simple code.


basically display a random line taken from a .txt file on a webpage.

example:

note pad file looks like this

123
abc
456
def

webpage displays "123", then if refreshed randomly chooses "def", and so on.
 
PHP:
<?php
$filename = '/path/to/file.txt';

$lines = file($filename);
$random_line = $lines[array_rand($lines)];

echo $random_line;

?>
 
Back
Top