Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
levenshtein. without native function
// Distancia Levenshtein en PHP (Sin usar la funciona nativa)
function lev($s,$t) {
$m = strlen($s);
$n = strlen($t);
for($i=0;$i<=$m;$i++) $d[$i][0] = $i;
for($j=0;$j<=$n;$j++) $d[0][$j] = $j;
for($i=1;$i<=$m;$i++) {
for($j=1;$j<=$n;$j++) {
$c = ($s[$i-1] == $t[$j-1])?0:1;
$d[$i][$j] = min($d[$i-1][$j]+1,$d[$i][$j-1]+1,$d[$i-1][$j-1]+$c);
return $d[$m][$n];
echo var_dump(lev('calle', 'calla'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.