27

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

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].