I am trying to create a program in laravel where a person can answer a question. In the controller, I want to check if the givenAnswer matches any of the actual answers.
I have seen a few things suggested online. The majority of people recommend using strpos. I have found however that it doesnt work as well as I would like it to.
For example, if one of the CORRECT answers is 'Quorin Halfhand', then strpos will show return true for answers such as "Quo, Half, Hand, alf," etc etc.
I would an option that lets me sanitize and state to what degree of error I would be willing to accept.
Is there anything out there that might be useful?
if (strpos($answers[$i], $request->answer) !== false) {
return 'an answer matches!';
} else {
return 'no answer mathches'
}
You could try computing the levenshtein distance between your two strings, and comparing the result with threshold of your choosing.