Josh (the blog)

I’ve delivered simple, clear and easy-to-use services for 20 years, for startups, scaleups and government. I write about the nerdy bits here.


@joahua

A 5 line quote script in PHP

…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…