How to display a random quote using php

Post Reply
User avatar
Saman
Lieutenant Colonel
Lieutenant Colonel
Posts: 828
Joined: Fri Jul 31, 2009 10:32 pm
Location: Mount Lavinia

How to display a random quote using php

Post by Saman » Fri Jul 15, 2011 6:21 pm

Displays a random quote on a web page. Quotes are picked from a list that you define.

Code: Select all

<?php 

/** 
 * Add this line of code in your page: 
 * <?php include "random_quote.php"; ?> 
 */ 

$quotes[] = "This is a quote"; 
$quotes[] = "This is another"; 
$quotes[] = "quote 3"; 
$quotes[] = "quote 4"; 
$quotes[] = "quote 5"; 
$quotes[] = "quote 6"; 

srand ((double) microtime() * 1000000); 
$randomquote = rand(0,count($quotes)-1); 

echo "<p>" . $quotes[$randomquote] . "</p>"; 

?>
Post Reply

Return to “PHP & MySQL”