Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way in php to find most similar strings?

Hell,

PHP has a lot of string functions like levenshtein, similar_text and soundex that can compare strings for similarity. http://www.php.net/manual/en/function.levenshtein.php

Which is the best for accuracy and performance?

like image 286
giorgio79 Avatar asked Feb 09 '11 16:02

giorgio79


1 Answers

similar_text has a complexity O(max(n,m)**3) and levenshtein a complexity of O(m*n), where n and m are the lengths of the strings, so levenshtein should be much faster. Both are 100% accurate, in that they give the same output for the same input, but the outputs for each function will differ. If you are using a different measure of accuracy, you'll have to create your own comparison function.

like image 170
Mark Rose Avatar answered Sep 25 '22 11:09

Mark Rose