Home  >  Article  >  Backend Development  >  levenshtein() function in PHP

levenshtein() function in PHP

PHPz
PHPzforward
2023-09-01 14:25:061350browse

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.

grammar

levenshtein(str1, str2, insert, replace, delete)

parameter

  • 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

return

levenshtein() function returns the Levenshtein distance between the two parameter strings. If one of the strings exceeds 255 characters, -1

is returned

Example

The following is an example -

Live Demo

<?php
   echo levenshtein("Welcome","elcome");
?>

Output

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete