11

wmatch

wmatch
SYNOPSIS

wmatch($word, $wl, $dlimit=0, $closest=true)

DESCRIPTION
CODE
  1. require_once 'strflat.php';
  2.  
  3. function wmatch($word, $wl, $dlimit=0, $closest=true) {
  4.     $word = strtolower(strflat($word));
  5.     $ret = false;
  6.  
  7.     foreach ($wl as $w) {
  8.         $d = levenshtein($word, strtolower(strflat($w)));
  9.  
  10.         if ($d < 0) {
  11.             continue;
  12.         }
  13.  
  14.         /* DON'T return immediately if $d is 0 to be case and accent insensitive */
  15.  
  16.         if ($d <= $dlimit) {
  17.             if ($closest && $d < $dlimit) {
  18.                 $ret=array($w);
  19.                 $dlimit=$d;
  20.             }
  21.             else {
  22.                 $ret[]=$w;
  23.             }
  24.         }
  25.     }
  26.  
  27.     return $ret;
  28. }

Comments

To add a comment, click here.