Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I have a database table with 3 columns; id, question and answer. On the front-end, I have a PHP application that shows questions to the user. The application would then compare the user input with the answer on the database.

Using only PHP, how do I loosely compare user's input with the record on the database and pass it as correct even though it is not a strict match? For example:-

Question: What is the structure of a water molecule? Answer on database: Hydrogen and oxygen Acceptable answers: Oxygen and hydrogen, hydrogen n oxygen, hydrogen & oxygen

share|improve this question

closed as unclear what you're asking by gnat, Martijn Pieters, MichaelT, Bart van Ingen Schenau, GlenH7 Apr 12 at 3:20

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

    
Unclear what help you need. Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it’s hard to tell what problem you are trying to solve or what aspect of your approach needs to be corrected or explained. See the How to Ask page for help clarifying this question. –  gnat Apr 11 at 6:38
1  
The question seems pretty clear... he's looking for a way to intelligently recognize correct answers that may be phrased in different ways. Not sure how feasable it is to do in a basic PHP script, but the question is clear. –  GrandmasterB Apr 11 at 14:44

1 Answer 1

up vote 4 down vote accepted

Levenshtein, SoundeX and Metaphone functions could be helpful.

You might need to break the original answers to words, in order to make a better comparison. Also taking out and, [space]n[space], & from both correct answers and the user input could lead you to a much better results.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.