PHP – want a random quote ?

I thought my site was missing something, perhaps a little bit of dynamic text , so now we have it ! Below my logo random one liner quotes will appear :cool:

I found the basics at totallyphp but it only read the quotes from an array, not a file, so: I added the file function & turned the script into a function :D

If you too want simple random quotes to include the source is here. The usage is simple, create a file called quotes.txt with quotes, a new one on each line (make it world readable) ; by default if you then call quotes.php it’ll choose a line & print the text… if you comment out echo randomquote(); you could include quote.php in other code :idea:

Here’s the code… enjoy !

# Where do I get my quotes from ?
$QUOTEFILE=”./quotes.txt”;

function randomquote() {
global $QUOTEFILE;
$quotes = file(“$QUOTEFILE”);

srand ((double) microtime() * 1000000);
$randomquote = rand(0,count($quotes)-1);

return $quotes[$randomquote];

}

echo randomquote();

rgds,

Nick


Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>