缺点
1.只适合英文单词
2.词库需要组合
1.只适合英文单词
2.词库需要组合
<?php
$dictionary = array(
"php", "javascript", "css"
);
$word = "jav scphp";
$best_match = $dictionary[0];
$match_value = levenshtein($dictionary[0], $word);
foreach($dictionary as $w) {
$value = levenshtein($word, $w);
if( $value < $match_value ) {
$best_match = $w;
$match_value = $value;
}
}
// input jav scphp
// output Did you mean the 'javascript' category? - 4
echo "Did you mean the '$best_match' category? - $match_value";