Ever want to display a quote, lyric, saying or whatever randomly on your site?
This simple PHP script does it. Fill it up with as many quotes as you want. Then, each time the page is loaded, the script randomly displays one quote.
Reload this page to see the random quote changer in action.
"You must think of failure and defeat as the springboards to new achievements or to the next level of accomplishment."
- Les Brown
Using this script on your site.
I use simple scripts like this as custom functions included in the head of my web page. Then, I can call the function without a lot of extra markup involved. Keeps my pages leaner and cleaner.
So, for this example, I would save the php code as a page called 'randomQuote.inc.php' and put it in a folder I call 'includes'.
Remember, you'll have to save your web page with the '.php' extension to get the script to work!
PHP code for Random Quote function
<?php
// this function displays a random quote
function randomQuote() {
$quotes[] = '"All successful men and women are big dreamers.
They imagine what their future could be, ideal in every
respect, and then they work every day toward their distant
vision, that goal or purpose."<br /><br />- Brian Tracy';
$quotes[] = '"You must think of failure and defeat as the
springboards to new achievements or to the next level of
accomplishment."<br /><br />- Les Brown';
$quotes[] = '"You can do anything you wish to do, have
anything you wish to have, be anything you wish to
be"<br /><br />- Robert Collier';
$quotes[] = '"The LORD is my strength and my might,
and he has become my salvation."<br /><br />- Exodus 15:2a';
$quotes[] = '"I have fought the good fight, I have
finished the race, I have kept the faith."<br />
<br />- 2 Timothy 4:7';
srand ((double) microtime() * 1000000);
$random_number = rand(0,count($quotes)-1);
echo '<p>' . ($quotes[$random_number]) . '</p>';
}
?>
HTML markup for Random Quote function
<?php
include 'includes/randomQuote.inc.php';
?>
<html>
<body>
<p>Lorem ipsum qui....</p>
<?php randomQuote();?>
<body>
<html>
I also have a random image script and random text script as well.


