Daily changing random quotes

This example shows how to display a random quote that changes only daily, monthly or just every year.

This is much better than quotes that change on every page load because it is search engine friendly and does not confuse the visitors.

Snippet information

Author:
Jonas John

License:
Public Domain

Language:
PHP

Created:
04/09/2007

Updated:
09/25/2007

Tags:
,


function RandomQuoteByInterval($TimeBase, $QuotesArray){
 
    // Make sure it is a integer
    $TimeBase = intval($TimeBase);
 
    // How many items are in the array?
    $ItemCount = count($QuotesArray);
 
    // By using the modulus operator we get a pseudo
    // random index position that is between zero and the
    // maximal value (ItemCount)
    $RandomIndexPos = ($TimeBase % $ItemCount);
 
    // Now return the random array element
    return $QuotesArray[$RandomIndexPos];
}
 
/*
** --> See the example section below for a
**     detailed instruction.
*/


Found a bug? Or do you have a better solution for this?
Feel free to leave a message:

Add a comment


Leave a comment

Mike G September 24, 2008 at 23:52
How can I display the quote every 15 seconds?
thanks