Добрый день. Имеется простенький чат+бот на 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.";
Хотелось бы реализовать чтение из csv файла. Допустим чтобы в csv было 2 стобца. Столбец того что пишем боту и столбец того что отвечает бот.
Код скрипта:
<?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; ?>
Есть идеи товарищи знатоки? В PHP пока новичок 🙁 Спасибо заранее!