Hi there, Just 10 day's ago, i got this crazy idea to make an artificial intelligence program in php. I called it PHP Artificial Intelligence Program or for short P.A.I.P . Currently planning
Some preview codes (v1)
- Talk to us as any other human would (random words like "how are you")
- GUI
- The database
- The actual site
- Learning new words as it communicates with us
- Answer questions
Some preview codes (v1)
PHP:
<?php
error_reporting(0);
$con = mysql_connect("localhost","root","haikal00");
if (!$con)
{
echo "<script>alert('Could not connect to database')</script>";
}
$db_selected = mysql_select_db("paip", $con);
if (!$db_selected)
{
echo "<script>alert('Couldn't select database')</script>";
}
?>
<html>
<head>
<title>PHP Artificial Intelligence Program</title>
<style>
#output
{
background-color: rgb(237, 239, 244);
margin-top: 1px;
font-family: 'lucida grande',tahoma,verdana,arial,sans-serif;
font-size: 11px;
line-height: 1.28;
width:300px;
height:50px;
border-radius:10px;
padding:6px;
}
</style>
<script>
function message(str)
{
if (str=="")
{
document.getElementById("output").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("output").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","message.php?message="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<center><h2>PHP Artificial Intelligence Program (PAIP)</h2></center>
<form>
Message: <input type="text" name="message" id="message" onkeyup="message(this.value)">
</form>
<div id="output">
<?php
$message = $_GET['message'];
$botname = "Test";
$sanitized_message = mysql_escape_string(stripslashes($message));
$search_phrase = mysql_query("SELECT answer FROM phrases WHERE phrase = '$sanitized_message'");
$search = mysql_fetch_assoc($search_phrase);
$search_rows = mysql_num_rows($search_phrase);
if ($search_rows > 0)
{
echo $botname ." : ". $search['answer'];
}
else
{
$insert_phrase = mysql_query("INSERT INTO phrases VALUES ('$sanitized_message')");
echo $botname ." : ". $sanitized_message;
}
?>
</div>
Last edited: