Zend - The PHP Company




Text

Add Code


Quote from fortune  

Type: code fragment
Added by: fath
Entered: 26/12/2001
Last modified: 01/12/2001
Rating: - (fewer than 3 votes)
Views: 4519
This simple script picks up random quotes from fortune's-like text files. Sentences are seperated by "%" char, fortune style database. The script could be used with any textfile, just watch out for the right needle and define()d include dir.


<?
/* Simple random quote
** Francesco Toscan, fathom@unixlover.com
*/

function quote_of($file)
{
  if (
stristr($file,"/")) die("Illegal file format");
  
define("INCDIR","docs/quotes/");
  
$char "%";
  
$lines file(INCDIR.$file);
  
$end count($lines);
  
mt_srand((double)microtime() * 1000000);
  
$num mt_rand("0"$end);
  
$i $num;
  while (!
stristr($lines[$i],$char))
  {
    
$i++;
    if (
$i == $end$i mt_rand("0"$end);
  }
  
$j $i +1;
  while (!
stristr($lines[$j],$char))
  {
    
$str .= $lines[$j];
    
$j++;
  }
  return 
$str;
}
?>


Usage Example


<!-- various HTML here -->

<pre>
<? print(quote_of("file.txt")); ?>
</pre>

<!-- The rest of your HTML -->


Rate This Script





Search



This Category All Categories