Location: PHPKode > scripts > ChatBot > chatbot/bot.php
<?

////////////////////////////////////////
// ChatBot v1						  //
// Alex Kovalyov | webta.net 2003     //
////////////////////////////////////////
		
include("config.php");

?>
<html>
<head>
<title>Chat bot</title>
<meta http-equiv="Content-Type" content="text/html;  charset=<? echo $cfg["encoding"] ?>">
<link href="bot.css" rel="stylesheet" type="text/css">
</head>

<body>

<div align="center">
  <form name="form1" method="post" action="bot.php">
  <table width="248" cellpadding="5" cellspacing="1" bgcolor="#6699CC">
    <tr>
      <td class="bt">ChatBot
v1</td>
    </tr>
    <tr>
      <td height="135" class="scr">
	  <div style="<? echo (($cfg["scrolling"]) ? "overflow: auto;height:100%;" : "") ?>">
	  	<?
		
		if ($_POST["submit"])
		{
			$a = answer();
			$out =  "Q: $ask<br>A: ".$a;
			$tile = ($cfg["scrolling"]) ? $tile : "";
			echo "$out<br>$tile";
			echo "<input name='tile' type='hidden' id='tile' value='$out<br>$tile'>";
		}
	  
	  	// answers
		function answer()
		{
			global $cfg, $ask;
			$ask = (empty($ask)) ? "<empty>" : $ask;
			$kick = array("?","\n");
			$ask = str_replace($kick,"",$ask);
			$f = file($cfg["answersfile"]);
			for ($i=0; $i<=count($f); $i++)
			{
				$an = split(";", $f[$i]);
				$a = $an[0];
				if (strstr($a,trim($ask)))
				{
					if ($wasone)
					{
						return("Please be more concrete");
					}
					array_shift($an);
					array_pop($an);
					$ai = rand(0, count($an)-1);
					// answering
					$wasone = true;
					$retval = $an[$ai];
				}
			}
			$retval = (empty($retval)) ? "I dont understand you. Please try again." : $retval;
			return $retval;
		}
	  ?>
	  	</div>
	  
	  </td>
    </tr>
    <tr>
      <td class="top">        <input name="ask" type="text" class="inp" id="ask" style="width:100%" value="Enter your question here" onFocus="if (this.value == 'Enter your question here') { this.value = '' }" onBlur="if (this.value == '') { this.value = 'Enter your question here' }" >
   </td>
    </tr>
    <tr>
      <td valign="top"><font face="Georgia, Times New Roman, Times, serif">
        <input name="sss" type="submit" class="btn" id="sss" value="Ask our bot">
        <input name="submit" type="hidden" id="submit" value="yup">
</font></td>
    </tr>
  </table>
  </form>
</div>
</body>
</html>
Return current item: ChatBot