[Person’s name] Leven;[Place name] [UK] Leven
php levenshtein() function syntax
Function:Calculate the edit distance between two strings
Syntax: int levenshtein (string $str1, string $str2, int $cost_ins, int $cost_rep , int $cost_del )
Parameters:
Parameters | Description |
str1 | Find one of the strings in the edit distance. |
str2 | Find another string in the edit distance. |
cost_ins | Define the number of insertions. |
cost_rep | Define the number of replacements. |
cost_del | Define the number of deletions |
Note: Edit distance refers to Between two strings, the minimum number of characters required to convert string str1 into str2 through operations such as substitution, insertion, and deletion.
php levenshtein() function example
<?php $data = "hello"; $res = "world"; echo levenshtein($data,$res); ?>
Run instance»
Click the "Run instance" button to view the online instance
Output:
4
<?php $str1 = "Learning PHP"; $str2 = "is a good choise"; echo levenshtein($str1,$str2); ?>
Run Instance»
Click the "Run Instance" button to view the online instance
Output:
14