levenshtein() function in PHP

PHPz
Release: 2023-09-01 14:26:01
forward
1328 people have browsed it

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)
Copy after login

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");
?>
Copy after login

Output

1
Copy after login

The above is the detailed content of levenshtein() function in PHP. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!