开发者

Magic 8 ball - text verification if almost the same?

开发者 https://www.devze.com 2023-04-01 18:20 出处:网络
I\'m building a fun kind of 8 ball website in PHP where people ask questions and get a yes or no answer.

I'm building a fun kind of 8 ball website in PHP where people ask questions and get a yes or no answer.

I'm looking to avoid the obvious mistakes like repeated questions... but I was hoping there was also a way of doing it to check if it almost the same. For example, if someone typed the following questions one after the other into the program, it should be able to give the same answer:

Will I be rich this year?
Will I be rich?
Will I be rich

Is开发者_如何转开发 this possible? I fault of the Eigen... thing, but not too familiar and these seem more complex than the usual.

Any help much appreciated.


save it in database or in session and compare them

if (in_array($question, $_SESSION['questions'])){
    echo $_SESSION['answers'][array_search($question, $questions)];
}
$_SESSION['qustions'][] = $question;
$_SESSION['answers'][] = (rand(1,10) == 10) ? 'yes' : 'no';

You can also use levenshtein or similar_text() function to calculate distances between questions

0

精彩评论

暂无评论...
验证码 换一张
取 消