R3m/framework Function reference string.levenshtein

{string.levenshtein(String $string1, String $string2)}
{string.levenshtein(String $string1, String $string2, Int $cost_insert=null, Int $cost_replace=null, Int $cost_delete=null)}

The Levenshtein distance is defined as the minimal number of characters you have to replace, insert or delete to transform string1 into string2.
The complexity of the algorithm is O(m*n), where n and m are the length of string1 and string2 (rather good when compared to similar_text(), which is O(max(n,m)**3), but still expensive).

If cost_insert, cost_replace and/or cost_delete are unequal to 1, the algorithm adapts to choose the cheapest transforms.
E.g. if $cost_insert + $cost_delete < $cost_replace, no replacements will be done, but rather inserts and deletions instead.

This function returns the Levenshtein-Distance between the two argument strings as an integer or -1, if one of the argument strings is longer than the limit of 255 characters.

More information:


Last modified: 2021-06-07

© 2021 universeorange.com