Good day. There is a simple chat + bot in php. But he goes over the block + answer set in the script:
$responses['what is your name'] = "My name is Mo-Pal."; $responses['tell me about yourself'] = "I am a chatbot. I'm still learning a lot of things so please forgive me if I can't answer you in some cases."; $responses["i'm fine"] = "Good. I'm happy about that."; I would like to implement reading from a csv file. Suppose there are 2 stobs in csv. The column of what we write to the bot and the column of what the bot responds to.
Script code:
<?php $responses['what is your name'] = "My name is Mo-Pal."; $responses['tell me about yourself'] = "I am a chatbot. I'm still learning a lot of things so please forgive me if I can't answer you in some cases."; $responses["i'm fine"] = "Good. I'm happy about that."; $q = $_GET["q"]; $response = ""; if ($q != "") { $q = strtolower($q); foreach ($responses as $r => $value) { if (strpos($r, $q) !== false) { $response = $value; } } } $noresponse = "Sorry I'm still learning. Hence my responses are limited. Ask something else."; echo $response === "" ? $noresponse : $response; ?> Any ideas for fellow experts? In PHP, while new :( Thanks in advance!