Find whether given strings are matching or not despite of having typing errors
I want to develop a script which checks whether string is matching with any string or not? I have table containing bulk data of rows.
recordId firstName lastName
1 jhon bagman
2 kerio control
3 michele levis
4 roger 开发者_如何学JAVA federrer
I had a bunch of strings as below
{
[0]=>kerio
[1]=>micehle
[2]=>roget
[3]=>jon
}
I want to find matching records from database anyhow by mysql-query
or php-code
.
Kerio must match kerio
micehle must match michele
roget must match roger
jon must match jhon
Means I want to search for matching string even though it contains typing errors as shown above.
I want this solution by any logic, means by running a mysql query
or by executing any "php code"
on all rows.
A good, but slow/computational expensive method, is the Levenshtein Distance. It lets you specify exactly how mangled a word has to be before it's not considered a match. MySQL doesn't support this directly, however, so you'd have to implement it in PHP.
A quick/dirty method directly in MySQL is to compare the SOUNDEX() values. It's quick, but also far less reliable:
SELECT ...
FROM table
WHERE SOUNDEX('kerio') IN (SOUNDEX(firstName), (SOUNDEX(lastName))
精彩评论