===== Syntax =====
int levenshtein(string $left, array $right)
//(PHP 4, PHP 5)//
^ $left | The first string to compare for Levenschtein distance. |
^ $right | The second string to compare for Levenschtein distance. |
^ RETURNS | The combined parts from the array as a single string with the **$separator** between the parts. |
===== What it Does =====
Levenschtein compares two strings by using a character-by-character comparison. It determines the
number of characters which need to be deleted, replaced, or inserted to transform one string into
the other. It returns a score indicating the similarity of the two strings with a zero being a
perfect match and higher numbers indicating more dissimilarities.
This function is limited to processing strings no longer than 255 characters.
===== Example =====
// compute the arc tangent for the angle 1.4 radians
$options = array('apple', 'banana', cherry');
$test = 'banter';
$minScore = -1;
$bestMatch = '';
foreach ($fruit in $options) {
$score = levenschtein($fruit, $test);
if ($score < $minScore || $minScore == -1) {
$minScore = $score;
$bestMatch = $fruit;
}
}
echo 'Best Match = ' . $bestMatch;
// outputs: "banana"