Return to Snippet

Revision: 26720
at May 7, 2010 23:58 by adampatterson


Initial Code
$dictionary = array(
		"php", "javascript", "css"
	);
 
$word = "japhp";
 
$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;
	}
}
 
echo "Did you mean the '$best_match' category?";

Initial URL
http://uk.php.net/levenshtein

Initial Description

                                

Initial Title
Calculate Levenshtein distance between two strings

Initial Tags

                                

Initial Language
PHP