note 100344 added to function.similar-text
| From: | JirkaSkuhrovec at osu1 dot php dot net | Date: | Sat, 09 Oct 2010 11:56:36 +0000 |
| Subject: | note 100344 added to function.similar-text | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-173101@lists.php.net to get a copy of this message | ||
Following functions is much more efficient for comparing short strings (say up to length 100). It
checks strings for containing same character PAIRS, rather than single characters. This better
captures differences in sensible text.
function getSimilarity($str1,$str2)
{
$arr1 = str_split($str1);
$arr2 = str_split($str2);
$i = 1;
$count = 0;
while(isset($arr1[$i]))
{
if(strstr($str2,$arr1[$i-1].$arr1[$i])) $count++;
$i++;
}
$i = 1;
while(isset($arr2[$i]))
{
if(strstr($str1,$arr2[$i-1].$arr2[$i])) $count++;
$i++;
}
return $count / (strlen($str1) + strlen($str2) -2);
}
----
Server IP: 69.147.83.197
Probable Submitter: 83.208.36.244
----
Manual Page -- http://www.php.net/manual/en/function.similar-text.php
Edit -- https://master.php.net/note/edit/100344
Del: integrated -- https://master.php.net/note/delete/100344/integrated
Del: useless -- https://master.php.net/note/delete/100344/useless
Del: bad code -- https://master.php.net/note/delete/100344/bad+code
Del: spam -- https://master.php.net/note/delete/100344/spam
Del: non-english -- https://master.php.net/note/delete/100344/non-english
Del: in docs -- https://master.php.net/note/delete/100344/in+docs
Del: other reasons-- https://master.php.net/note/delete/100344
Reject -- https://master.php.net/note/reject/100344
Search -- https://master.php.net/manage/user-notes.php