Random Generator - PHP
I just answered a post in the HTML forum about a random generator. I figured I'd make one in PHP and post it for all to use.
I took this from my site. If you can read, you can also figure out I wrote is as a Quote Generator. But you, my friend, my modify it to generate whatever your heart desires. Enjoy.
<?
/* Random Quote Generator */
/* Written by: Mark "Max Albert" Hensler */
/* template
$rqNum++;
$quote[$rqNum] = '';
$author[$rqNum] = '';
*/
/* REMEMBER to escape all single quotes! */
$rqNum = "0";
$quote[$rqNum] = 'Women have their faults.<BR>Men have only two.<BR>Everything they say and<BR>everything they do.';
$author[$rqNum] = 'unknown';
$rqNum++;
$quote[$rqNum] = 'Hire a teenager now while they still know it all.';
$author[$rqNum] = 'unknown';
$rqNum++;
$quote[$rqNum] = 'As men grow older, they experience a mid-life crisis, while women experience a mental pause.';
$author[$rqNum] = 'Max';
$rqNum++;
$quote[$rqNum] = 'An apple a day will keep Windows away.';
$author[$rqNum] = 'unknown';
/*
CONVERSIONS
' = '
*/
/* The total number of quotes */
$TotalQuotes = $rqNum + 1;
/* Initialise the random number generator */
Srand(date("s"));
/* Multiply random number by number of quotes [$TotalQuotes] */
$n = Rand() % $TotalQuotes;
$quote = $quote[$n];
$author = $author[$n];
?>
<table border=0 cellpadding=0 cellspacing=0 width=150>
<tr>
<td>
<!-- Quote #<?echo $n;?> of <%echo $TotalQuotes;%> -->
<font color=000000 face="verdana,arial" size=2>
<? echo $quote; ?>
</font>
<div align=right>
<font color=000000 face="verdana,arial" size=1><I>
<? if ($author != "unknown"){ echo $author;} ?>
</I></font>
</div>
</td>
</tr>
</table>
Mark Hensler
If there is no answer on Google, then there is no question.