PHP – Random quote
First published on Ka of Isis 140423
Note: As github.io
(where this website lives) does not support PHP, the result shown in this article, is a simulation.
The PHP
$quotes = array("1st quote","2nd quote","3rd quote","4th quote","5th quote");
$rndm = rand(0,count($quotes)-1);
echo $quotes[$rndm];
Below, the PHP script is implemented in a regular HTML paragraph complete with italicized text and line breaks between quote and quotee, and enriched with CSS to fit the overall page layout.
<p class="quote"><?php
$quotes = array("‘Of the thirty-six ways out of difficulty, the best way of all is to run away.’<br>– Chinese proverb","‘Strange about learning; the further I go the more I see that I never knew even existed. A short while ago I foolishly thought I could learn everything – all the knowledge in the world. Now I hope only to be able to know of its existence, and to understand one grain of it.’<br>– Charlie in Daniel Keyes’ <i>Flowers for Algernon</i>","‘Men. It is a shame to us women that we make them.’<br>– Elderly Spanish woman in Ernest Hemingway’s <i>For whom the bell tolls</i>","‘There are three kinds of lies: Lies, damned lies, and statistics.’<br>– Quotee disputed","‘Hope I die before I get old.’<br>– Pete Townshend in <i>My generation</i>");
$rndm = rand(0,count($quotes)-1);
echo $quotes[$rndm];
?></p>
The output
‘Men. It is a shame to us women that we make them.’
– Elderly Spanish woman in Ernest Hemingway’s For whom the bell tolls
Pros and cons
When PHP alone is used to lift the heavy load, all search and programming routines take place in a ‘closed’ environment obviating the necessity to translate between different file formats like PHP vs XML, or PHP vs TXT. Communication between client (browser) and server is kept to a minimum, saving bandwith. Another advantage is that it is difficult to rip a complete collection of quotes, images or what have you, as complete array contents are not revealed to the user. The PHP-file and its contents are inaccessible and only used internally by the server to build an HTML file. The client (customer), however, is dependent on the developer to update the document.