This is a discussion on How to Calculate Similarity Percentage with Levenshtein function within the PHP General forums, part of the PHP Programming Forums category; Hi, I'm trying to obtain the similarity percentage for 2 Strings when using the Levenshtein function but the percentages ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi,
I'm trying to obtain the similarity percentage for 2 Strings when using the Levenshtein function but the percentages doesn't seem to match the percentage returned by similar_text($str1,$str2,$match_percent); Below is what I use to calculate the similarity percentage $dist = levenshtein($str1,$str2); $str1len = strlen($str1); $str2len = strlen($str2); if($str1len > $str2len) { $pct = ($str1len - $dist)/$str1len; } else { $pct = ($str2len - $dist)/$str2len; } $pct = $pct*100; What am I missing from the calculation? Thanks. |