note 83501 added to function.levenshtein

From: Date: Wed, 28 May 2008 20:03:50 +0000
Subject: note 83501 added to function.levenshtein
Groups: php.notes 
Request: Send a blank email to php-notes+get-139956@lists.php.net to get a copy of this message
Simple levenshtein function without string length limit ... <?php function levenshtein2($str1, $str2, $cost_ins = null, $cost_rep = null, $cost_del = null) { $d = array_fill(0, strlen($str1) + 1, array_fill(0, strlen($str2) + 1, 0)); $ret = 0; for ($i = 1; $i < strlen($str1) + 1; $i++) $d[$i][0] = $i; for ($j = 1; $j < strlen($str2) + 1; $j++) $d[0][$j] = $j; for ($i = 1; $i < strlen($str1) + 1; $i++) for ($j = 1; $j < strlen($str2) + 1; $j++) { $c = 1; if ($str1{$i - 1} == $str2{$j - 1}) $c = 0; $d[$i][$j] = min($d[$i - 1][$j] + 1, $d[$i][$j - 1] + 1, $d[$i - 1][$j - 1] + $c); $ret = $d[$i][$j]; } return $ret; } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 78.2.45.190 ---- Manual Page -- http://www.php.net/manual/en/function.levenshtein.php Edit -- https://master.php.net/note/edit/83501 Del: integrated -- https://master.php.net/note/delete/83501/integrated Del: useless -- https://master.php.net/note/delete/83501/useless Del: bad code -- https://master.php.net/note/delete/83501/bad+code Del: spam -- https://master.php.net/note/delete/83501/spam Del: non-english -- https://master.php.net/note/delete/83501/non-english Del: in docs -- https://master.php.net/note/delete/83501/in+docs Del: other reasons-- https://master.php.net/note/delete/83501 Reject -- https://master.php.net/note/reject/83501 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#139956) next »