Home > Article > Backend Development > levenshtein() function in PHP
levenshtein() function is used to calculate the Levenshtein distance between two strings. Edit distance is the number of characters that must be replaced, inserted, or deleted to convert the first string into the second string. This function is not case sensitive.
levenshtein(str1, str2, insert, replace, delete)
str1 - The first string to compare
str2 - The second string to compare
Insertion - Cost of inserting characters
Replacement - Cost of replacing a character
Delete - Cost of deleting a character
levenshtein() function returns the Levenshtein distance between the two parameter strings. If one of the strings exceeds 255 characters, -1
is returnedThe following is an example -
Live Demo
<?php echo levenshtein("Welcome","elcome"); ?>
1
The above is the detailed content of levenshtein() function in PHP. For more information, please follow other related articles on the PHP Chinese website!