S sussah Newbie Joined Dec 1, 2011 Messages 37 Reaction score 2 Jan 8, 2012 #1 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.
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.
C chatmasta Junior Member Joined Sep 1, 2007 Messages 122 Reaction score 38 Jan 8, 2012 #2 PHP: <?php $filename = '/path/to/file.txt'; $lines = file($filename); $random_line = $lines[array_rand($lines)]; echo $random_line; ?>
PHP: <?php $filename = '/path/to/file.txt'; $lines = file($filename); $random_line = $lines[array_rand($lines)]; echo $random_line; ?>
S sussah Newbie Joined Dec 1, 2011 Messages 37 Reaction score 2 Jan 8, 2012 Thread Starter Thread Starter #3 Thanks man, flawless