PHP levenshtein() Function
PHP levenshtein() Function
The levenshtein() function in PHP calculates the Levenshtein distance between two strings.
Syntax
levenshtein ( string $str1 , string $str2 , int $cost_ins , int $cost_rep , int $cost_del )
Parameter
str1(required)- This parameter signifies one of the strings being evaluated for Levenshtein distance.
str2(required)- This parameter signifies one of the strings being evaluated for Levenshtein distance.
cost_ins(optional)- This parameter specifies the cost insertion.
cost_rep(optional)- This parameter specifies the cost of replacement.
cost_del(optional)- This parameter specifies the cost of deletion.
Return
This function returns the Levenshtein-Distance between the two specified strings or returns -1, if one of the argument strings is longer than the limit of 255 characters.
Example 1
Output
1
Example 2
Output
4
Example 3
Output
120