I need help with something. I am creating a very basic web page that allows me to view randomly generated text from several files. I have found scripts that allow me to generate a random text line from one file, but what i need is to generate a full text document within a text box on my website. I would like a button at the bottom that when clicked will pull up new text every time its clicked. Each text will be a seperate txt file on the server. Does anyone know of an easy way to do this?
Here is a function that loads articles from a folder randomly (from txt, htm files) and can also insert some variables like #pagename# #site#: function article_load($folder,$max) { global $article_show_title; if ($folder[strlen($folder)]!="/") $folder.="/"; $n=0; $handle=opendir($folder); while (($file = readdir($handle)) !==false) { $ext=substr($file, -3); if ($file && ($file != ".") && ($file != "..") && (!is_dir($folder.$file))) if ($ext=="txt"||$ext=="tml"||$ext=="htm") { $fname[++$n]=$file; $added[$n]=0; } } global $HTTP_SERVER_VARS; $fullname=strtoupper($HTTP_SERVER_VARS['SERVER_NAME']); if($fullname=="LOCALHOST") $name=$fullname; else { if (substr($fullname,0,4)=='WWW.') $name=substr($fullname,4); else $name=$fullname; } $temp = substr($name, 0, 1); $name = strtolower($name); $name = $temp . substr($name,1); $pagename=substr($_SERVER['SCRIPT_NAME'],1,-4); $pagename=str_replace("_"," ",$pagename); $pagename=str_replace("-"," ",$pagename); $pagename=ucwords($pagename); $result=""; if ($n) for ($i=0;$i<$max;$i++) { $k=rand(1,$n); if (!$added[$k]) { $result.="<BR><BR>"; if ($article_show_title) { $ftitle=substr($fname[$k],0,strpos($fname[$k],".",1)); $ftitle=str_replace("_"," ",$ftitle); $ftitle=str_replace("-"," ",$ftitle); $ftitle=ucwords(trim($ftitle)); $result.="<u>$ftitle</u><BR>"; } $article= trim(join("",file($folder.$fname[$k]))); $article=str_replace("#pagename#",$pagename,$article); $article=str_replace("#site#",$name,$article); $article=str_replace("\r\n","<BR>",$article); $article=str_replace("<BR><BR>","<BR>",$article); $result.="$article"; $added[$k]=1; } } return $result; } Code (markup):