开发者

Magic 8 ball - text verification if almost the same?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜