Code :
// hide source code
// hide line numbers
// hide source code
// hide line numbers
1 <?php
2
3 // string randquote(string $infile, string $delim):
4 //
5 // generates a random quote, separated by $delim.
6 // $delim defaults to the fortune-style double-% on its own line (n%%n).
7
8 function randquote($infile, $delim = "n%%n")
9 {
10 // error trapping!
11 if(!IsSet($infile))
12 {
13 die ("You didn't specify a parameter for $infile!");
14 }
15 // attempt to open $infile
16 if(!file_exists($infile))
17 {
18 die ("$infile was not found! check your paths!");
19 }
20 else
21 {
22 $fp = fopen($infile, "r")
23 or die ("Error opening file!");
24 }
25 // okay, let's get going.
26 $contents = fread($fp, filesize($infile));
27 $quote_arr = explode($delim,$contents);
28 fclose($fp);
29 // feed the Randomness Monster (tm)
30 srand((double)microtime()*1000000);
31 // generate random quote index
32 $quote_index = (rand(1, sizeof($quote_arr)) - 1);
33 // get quote at $quote_index and return it
34 $herequote = $quote_arr[$quote_index];
35 return $herequote;
36 }
37 ?>
Donation:If you like our free quality work, make a donation by using Paypal and tell us what you would like to see improved on our site for the next few months. |
|
No comments yet













Page Info












