A 5 line quote script in PHP
26 Mar 2005…mainly because Ben has taken too long to write his own (I don’t think he was trying, but meh… no more excuses!)
18 lines of comments, and 5 lines of code. If this is too hard to use, you shouldn’t be using PHP (or any programming language, for that matter!)
<?php #—–Simple Random Quote script——-#
Place this file somewhere servable,
and stick a file “quotes.txt” in the
same directory as it. Alternatively,
change the $quotesfile variable to
something desirable.
#
IMPORTANT: Quotes file must be
server readable. Obvious, but often
overlooked.
#
quotes.txt format is:
Quotation::Author
Use one entry per line only.
#
Output from the regex replacement is:#
<p>Quotation
Author</p>#
#————————————–#
$quotefile = “quotes.txt”;
if ($quotes = file($quotefile)) {
echo eregi_replace(“([^[])::([^[])”,”<p>1
2</p>”, $quotes[array_rand($quotes)]);
} else{
echo ‘An error has occurred, no quotes are available at this time.’;
} ?>
I hope WordPress doesn’t mess that up…