I'm not a php expert but I do like to sometimes download scripts (with permission) and make use of them for my websites. I have got the following script working, however its only outputting one result even when you select it to output multiple. Can anyone give me advice on how to get it to work correctly?
<html>
<HEAD>
<TITLE>
Ahnicus Elven Name Generator
</TITLE>
</HEAD>
<body>
<CENTER>
<B>
<FONT SIZE=5>Ahnicus Elven Name Generator</FONT>
</B>
</CENTER>
<?php
//Initialize
srand((double)microtime()*1000000);
if ($selGenCount < 1)
{
$selGenCount=1;
}
//Data setup
$strWords = array();
$intWordCode = array();
$intFetchCode = array();
$strFetchText = array();
$objData=fopen("elfdat.dat","r");
if(!($objData))
{
print("File could not be opened.");
exit;
}
$intState=0;
$bOrgLevel=false;
while (!feof($objData))
{
$strLine=fgets($objData,1024);
if (strlen($strLine)>1)
{
if (strlen(strrpos($strLine,"\n"))>0)
{
$strLine=substr($strLine,0,strlen($strLine)-2);
}
}
//First, see if there is a comment (//) line.
//Then, see if it is a categorization (--) line. This changes state.
//If it is neither, check the states to see what we're doing.
if (substr($strLine,0,2)=="//")
{
//Do nothing.
}
elseif ($strLine=="--ORGANIZATION")
{
$intState=1;
$bOrgLevel=false;
}
elseif ($strLine=="--VOCABULARY")
{
$intState=2;
}
else
{
if (count(strlen($strLine))>0)
{
switch($intState)
{
case 0:
//Nothing
break;
case 1:
if ($bOrgLevel==true)
{
$strFetchText[count($strFetchText)] = explode(",",$strLine);
$bOrgLevel=false;
}
else
{
$intFetchCode[count($intFetchCode)] = explode(",",$strLine);
$bOrgLevel=true;
}
break;
case 2:
if (strlen(strpos($strLine,","))>0)
{
$strHolder=strtolower(chop(trim(substr($strLine, (strpos($strLine,",")+1), strlen($strLine)))));
$bTrump=($strHolder=="true");
$strLine=chop(trim(substr($strLine, 0, (strpos($strLine,",")))));
$strWords[count($strWords)] = $strLine;
$intWordCode[count($intWordCode)] = intval($strHolder);
}
else
{
$strWords[count($strWords)] = $strLine;
$intWordCode[count($intWordCode)] = 0;
}
break;
}
}
}
}
fclose($objData);
?>
<HR>
<form action="elf.php" method="POST" name="frmControls">
<p>Number of Elven names to be Generate: <select name="selGenCount" size="1">
<?php
if ($selGenCount==1)
{
print("<option value==1 selected>1</option>");
}
else
{
print("<option value==$intLooper>$intLooper</option>");
}
for ($intLooper=20;$intLooper<105;$intLooper+=5)
{
if ($selGenCount==$intLooper)
{
echo("<option value==$intLooper selected>$intLooper</option>");
}
else
{
print("<option value==$intLooper>$intLooper</option>");
}
}
?>
</select>
<input type="submit" name="subGenerate" value="Generate"></p>
</form>
<HR><?php
function GetWord($intNeedGet,$intAlreadyHave)
{
global $intWordCode;
$bStop = false;
do
{
if (count($intWordCode)==1)
{
$intReturnNumber=0;
}
else
{
$intReturnNumber=rand(0,count($intWordCode)-1);
}
$bStop=true;
if (($intWordCode[$intReturnNumber] & $intNeedGet)!=$intNeedGet)
{
$bStop=false;
}
for ($intLooper=0;$intLooper<count($intAlreadyHave);$intLooper++)
{
if ($intReturnNumber==$intAlreadyHave[$intLooper])
{
$bStop=false;
}
}
}
while ($bStop==false);
return($intReturnNumber);
}
function GenTerm()
{
//Get access to the fetch array.
global $intFetchCode;
global $strFetchText;
global $strWords;
settype($strTerm, "string");
$intLooper=0;
//Only a 25% chance of a title
if ((count($intFetchCode)-1)==0)
{
$intWhichFetch = 0;
}
else
{
$intWhichFetch = rand(0,count($intFetchCode)-1);
}
$intArrayHold=array();
for ($intLooper = 0 ; $intLooper < count($intFetchCode[$intWhichFetch]) ; $intLooper++)
{
$intArrayHold[$intLooper]=-1;
}
for ($intLooper = 0 ; $intLooper < count($intFetchCode[$intWhichFetch]) ; $intLooper++)
{
$intArrayHold[$intLooper]=GetWord($intFetchCode[$intWhichFetch][$intLooper], $intArrayHold);
}
$strTerm=$strFetchText[$intWhichFetch][0];
for ($intLooper = 0 ; $intLooper < count($intFetchCode[$intWhichFetch]) ; $intLooper++)
{
$strTerm .= $strWords[$intArrayHold[$intLooper]];
$strTerm .= $strFetchText[$intWhichFetch][$intLooper+1];
}
return($strTerm);
}
if ($selGenCount > 1)
{
print("<B>Creation:</B><BR>");
}
else
{
print("<B>Creations:</B><BR>");
}
$aGenHold=array();
for ($intLooper=0;$intLooper<$selGenCount;$intLooper++)
{
$aGenHold[$intLooper]=GenTerm();
}
sort($aGenHold);
for ($intLooper=0;$intLooper<$selGenCount;$intLooper++)
{
print($aGenHold[$intLooper]);
print("<BR>");
}
?>
<HR>
<CENTER>
<B>
<FONT SIZE=2>Code thanks to <a href="http://www.seventhsanctum.com" target="_blank">SeventhSanctumTM</a></FONT>
</B>
</CENTER>
</body>
</html>
Here is where the script can be called:
http://www.ahnicus.com/files/elven/elf.php
Thanks