Menu Samaritan's Purse

LEVENSHTEIN

Calculate Levenshtein distance between two strings

The Levenshtein distance is defined as the minimal number of characters you have to replace, insert, or delete to transform str1 into str2.

SYNTAX

levenshtein ( string $str1 , string $str2 ) : int
levenshtein ( string $str1 , string $str2 , int $cost_ins , int $cost_rep , int $cost_del ) : int

PARAMETERS

str1

One of the strings being evaluated for Levenshtein distance.

str2

One of the strings being evaluated for Levenshtein distance.

cost_ins

Defines the cost of insertion.

cost_rep

Defines the cost of replacement.

cost_del

Defines the cost of deletion.

RETURN

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

EXAMPLES

1

0

2

8

3

8

4

35

5

input: carrrot
closest match: carrot

PHP