Creating a Random Quote Script
Posted on August 29, 2008, Filled under PHP,
Bookmark it
This is a Random Quote Script.
<?php
// Credits: http://www.bitrepository.com/
srand((float) microtime() * 10000000); // IF PHP Version < 4.2.0
// Create the array first
$quotes = array();
// Fill it with quotes
$quotes[] = array('quote' => 'Time is money.',
'author' => 'Benjamin Franklin');
$quotes[] = array('quote' => "And in the end, it's not the years
in your life that count.
It's the life in your years.",
'author' => 'Abraham Lincoln');
$quotes[] = array('quote' => "The secret to creativity is knowing
how to hide your sources.",
'author' => 'Albert Einstein');
$quotes[] = array('quote' => "A mind that is stretched by a new experience
can never go back to its old dimensions.",
'author' => 'Oliver Wendell Holmes');
/*
NOTE: To add more quotes just continue filling the array like this:
$quotes[] = array('quote' => "THE QUOTE HERE",
'author' => "QUOTES'S AUTHOR");
*/
$rand_key = array_rand($quotes, 1);
$quote_array = $quotes[$rand_key];
$quote = $quote_array['quote'];
$author = $quote_array['author'];
echo $quote.' - '.$author;
?>
Do you wish to receive the latest updates as soon as they are posted? Get our RSS Feed or Subscribe to the Newsletter!
- August 29, 2008
- article by Gabriel C.
- 2 comments
Sponsors
Related Posts
-
Show random image(s) from a directoryat September 21, 2008 with 3 comments
-
PHP: How to select a random value from an array using a specified rangeat September 20, 2008
-
Display Values from an Array in Random Orderat October 2, 2008
-
How to generate a random password in PHPat August 29, 2008 with 2 comments
-
How to make a PHP download script without disclosing the location of the filesat September 20, 2008 with 5 comments

2 Replies to "Creating a Random Quote Script"
August 31, 2008 at 8:39 AM
I doubt many people will be using a version of PHP lower than 4.2.
August 31, 2008 at 11:36 AM
Yes, but it’s good to be there just in case. A good example can be seen at this address: http://www.php.net/array_rand.