Created
October 11, 2012 11:19
-
-
Save tomjn/3871705 to your computer and use it in GitHub Desktop.
PHP Levenshtein distance methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Example { | |
public function length(){ | |
return 5; | |
} | |
public function __call($name,$arguments){ | |
$methods = get_class_methods($this); | |
$ldist = 9999; | |
$currmethod = $name; | |
foreach($methods as $m){ | |
$distance = levenshtein($name,$m); | |
if($distance < $ldist){ | |
$currmethod = $m; | |
$ldist = $distance; | |
} | |
} | |
return call_user_func(array($this,$currmethod),$arguments); | |
} | |
} | |
$example = new Example(); | |
echo $example->elngth(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment