Php levenshtein
From w3cyberlearnings
Contents |
PHP function levenshtein
This function returns the Levenshtein distance between two strings.
The Levenshtein distance is defined as the minimal number of characters need to replace, insert or delete to transform str1 into str2.
Syntax levenshtein
- str1: string input
- str2: string input
- insert: defined the cost of insertion
- replace: defined the cost of replacement
- delete: defined the cost of deletion
levenshtein(str1, str2, insert, replace, delete);
Example 1
<?php $str1 = "Great Leader"; $str2 = "Great Manager"; echo levenshtein($str1, $str2); ?>
Output
4
Example 2
<?php $str1 = "Great Leader"; $str2 = "Great Laeder"; echo levenshtein($str1, $str2); ?>
Output
2
Example 3
<?php $str1 = "Great Leader"; $str2 = "Great Laeder"; echo levenshtein($str1, $str2,2,4,4); ?>
Output
6
Example 4
<?php $str1 = "Great Leader"; $str2 = "Great Laeder"; echo levenshtein($str1, $str2,4,4,4); ?>
Output
8