Posted by PHPGB on 11/15/48 11:24
<comp.lang.php , , google@sigol.co.uk>
<1124402050.422587.203050@g14g2000cwa.googlegroups.com>
<18 Aug 2005 14:54:10 -0700>
> Hi I'm a newbie. I want to create a simple script that reads a text
> file (quotes.txt) and picks a quote from the file at random. There will
> be one quote per line in the file. Any help would be greatly
> appreciated.
>
I have my random quote stuff currently in the config file and i've been
meaning to convert it to a text file .
Its your lucky day as I had to write the code anyway .
phpgb_rnx_random.php can be any text file you want and the file
extension used doesnt matter .
<?php
$phpgb="phpgb_rnx_random.php";
$filename=$phpgb;
$fp=fopen($filename,"r");
$toke=0;
while (!feof($fp))
{
$jack[$toke]=fgets($fp);
$toke=$toke+1;
}
$toke=$toke-2;
fclose($fp);
$zzz=(rand()%$toke);
print "There are $toke random lines <br>";
print "Random Number = $zzz <br>";
print "$jack[$zzz] <br>";
?>
--
www.phpguestbook.co.uk
Navigation:
[Reply to this message]
|