Posted By

adampatterson on 05/07/10


Tagged

words String levenshtein


Versions (?)

Calculate Levenshtein distance between two strings


 / Published in: PHP
 

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

  1. $dictionary = array(
  2. "php", "javascript", "css"
  3. );
  4.  
  5. $word = "japhp";
  6.  
  7. $best_match = $dictionary[0];
  8. $match_value = levenshtein($dictionary[0], $word);
  9.  
  10. foreach($dictionary as $w) {
  11. $value = levenshtein($word, $w);
  12. if( $value < $match_value ) {
  13. $best_match = $w;
  14. $match_value = $value;
  15. }
  16. }
  17.  
  18. echo "Did you mean the '$best_match' category?";

Report this snippet  

You need to login to post a comment.