Hallo allemaal,
Ik ben bezig om onze starwars jk3 (quake based) bot om te zetten in php , zodat iedereen er gebruik van kan maken.
het moet dus zo worden dat als iemand een zin in het input box typt , hij de overeen komende vragen en antwoorden opzoekt , daaruit weer preciezer zoekt en dan een van de meest overeenkomende antwoorden terug naar de game server stuurd via rcon.
Voorbeeld:
iemand zegt: where the hell is the shop , dan zoekt hij voor: where , the , hell , is , the ,shop
en moet hij alle resultaten echoén om te laten zien of de eerste stap goed werkt.
Het werkt alleen nog niet helemaal dit is wat ik tot nu toe heb in de database:
id |question | answer
1 |where shop |The shop is near the bar.
2 |what the hell | This is heaven!
3 |Where is bar |The bar is near the shop.
4 |Is difficult bot |No it is not difficult to be a bot.
5 |go home |No I don't want to go home!
Dit is mijn script:
<?php require ('includes/connect.php') ;?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Bot</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<?php
If (!isset($_POST['submit'])){
?>
<table style="width: 100%;">
<tr>
<form action="index.php" method="post"></td>
<td></td>
</tr>
<tr>
<td style="width: 40%;">Input</td>
<td style="width: 60%;"><input type="text" name="input" size="30" />
</tr>
<tr>
<td style="width: 40%;"></td>
<td style="width: 60%;"><input style="width:30%;" type="submit" name="submit" value="Submit" /></form></td>
</tr>
</table>
<?php
}Else{
$inputnot = trim($_POST['input']);
$inputnot = str_replace('.',' ',$inputnot);
$inputnot = str_replace('?',' ',$inputnot);
$inputnot = str_replace(',',' ',$inputnot);
$inputnot = str_replace(':',' ',$inputnot);
$inputnot = str_replace(';',' ',$inputnot);
$inputnot = str_replace(' ',' ',$inputnot);//moet 2 keer om de "bla , bla" dingen op te lossen
$inputnot = str_replace(' ',' ',$inputnot);
$inputarray = explode(" ", $inputnot);
$aantalwrd = count($inputarray); //aantal woorden tellen
$count = -1;
while ($count < $aantalwrd -1) //Opent een while loop waarvan de commandos uitgevoerd worden totdat $count gelijk is aan het aantal woorden in de array.
{
$count++;
If ($count == 0){
$newarray[$count] = " like '%".$inputarray[$count]."%'"; //voor eerste woord in de zin like
}ELSE{
$newarray[$count] = " OR question like '%".$inputarray[$count]."%'";// voor andere woorden or like
}
}
for ($count = -1; $count < $aantalwrd -1; $count++)
{
$achterelkaar = $achterelkaar.$newarray[$count];// alles uit de array in 1 variabele stoppen
}
$query =(mysql_query('SELECT question FROM general WHERE question '.$achterelkaar.'')or die ( mysql_error( ))); //query uitvoeren
while($record = mysql_fetch_object($query)){
echo $record->question;
} //resultaten laten zien
//<META HTTP-EQUIV="refresh" content="10; url=index.php">
}
?>
</body>
</html>
hier is een voorbeeld van wat ik tot nu toe heb:
http://bot.pipobona.com/index.php
het werkt nog niet goed , als ik iets intyp bijvoorbeeld: where is the shop , dan echoéd hij niks , zelfs als ik letterlijk : where shop intyp doet hij niks.
wat doe ik fout? ik hoop dat jullie het antwoord weten
1.137 views