Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP :: handle typos in search

Tags:

regex

php

search

I have a field to input your friend's name and search him up to add him as friend.
The problem is that if you are not sure how to spell his name like:
Kris instead of Chris for example.
I think the right way to do this is use RegEx but I don't know how...

  • How can I handle those kind of typos in PHP ?
    (if it isn't possible in PHP then tell me how to do it in jQuery)

like image 941
user484957 Avatar asked Jan 30 '26 06:01

user484957


1 Answers

I think a regex is not a good approach to check for typos and similar strings. I would consider something like levenshtein - PHP even has a native function for that, levenshtein.

EDIT: Depending on what you're looking for, there are other algorithms too that are also native in PHP: soundex (although considered superseded by newer approaches like Double Metaphone), metaphone, similar_text.

like image 131
EboMike Avatar answered Jan 31 '26 19:01

EboMike



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!