Re: randomly random

From: Date: Tue, 05 Apr 2011 15:14:47 +0000
Subject: Re: randomly random
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-312274@lists.php.net to get a copy of this message
On 4/5/2011 7:07 AM, Kirk Bailey wrote: > OK gang, to spew a single line from a file of fortune cookies, I want to read it > and echo one line. While I found a 4 line code which gets it done, I thought > there was a preexisting command to do exactly that. Any feedback on this? > No, but it can be done in one line: <?php echo array_rand(@file(@$filename), 1); # if you wanted to do a couple checks, you could do the following if ( is_file(@$filename) && filesize($filename) > 0 ) echo array_rand(file($filename), 1); ?> Jim Lucas

« previous php.general (#312274) next »