tags:

views:

34

answers:

2
+5  A: 

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.

EboMike
+1, although `metaphone`s are probably more to the point then levenshtein and others. They are _language specific_ though, if the current language isn't english another metaphone algorithm should be used.
Wrikken
Double Metaphone tries to include many other languages as well (there's an implementation available for PHP), although it's questionable how well it works in practice.
EboMike
+2  A: 

Regex isn't appropriate for this. Your best bet is to create a set of names that group similar names with their spellings. So the name Chris would search for Kris, Chris, Kriss, etc.

A hash_map is probably a good choice. Levenshtein distance could sorta work, but you'll get a lot of false positives: (Camella vs Pamella for example).

JoshD