Possible Duplicate:
String similarity in PHP: levenshtein like function for long strings
I have my subject string
$subj = "Director, My Company";
and a list of multiple strings to be compared:
$str1 = "Foo bar";$str2 = "Lorem Ipsum";$str3 = "Director";
What I want to achieve here is to find the nearest string related to $subj. Is it possible to do it?
The
levenshtein()function will do what you expect. The Levenshtein algorithm calculates the number of insert and replace actions being required to transform some string into another. The result is called anedit distance. The distance can be used to compare strings as you requested.This example is derived from the documentation of the PHP
levenshtein()function.Scripts output is
Good Luck!