Bug #62648 [Opn]: similar_text() returns wrong values

From: Date: Sun, 29 Jul 2012 05:48:15 +0000
Subject: Bug #62648 [Opn]: similar_text() returns wrong values
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-172309@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=62648&edit=1 ID: 62648 User updated by: normadize at gmail dot com Reported by: normadize at gmail dot com Summary: similar_text() returns wrong values Status: Open Type: Bug Package: Strings related Operating System: Linux, Win32 PHP Version: 5.3.15 Block user comment: N Private report: N New Comment: Note that besides giving different results when swapping arguments, it gives wrong results sometimes completely. Here's an example: <?php $s1 = 'biocompatibilitystudiesofironoxidedextrinthinfilmsbacdetundgakslfnnd'; $s2 = 'studyofironoxidenanoparticlescoatedwithdextrinobtainedbybcgagsfddteuhdgavdjfkdbey'; echo similar_text($s1, $s2); echo ","; echo similar_text($s2, $s1); ?> Gives 34,32 instead of 35,35. Longest common substring is "studofironoxidedextrintinbcdtudgafd" which is 35 chars long. I have written a small custom PHP extension that I compile and load in all my PHP deployments for speed because a PHP implementation of the longest common substring algorithm in PHP is painfully slow. My extension is based on suffix trees rather than recursive calls, which is generally faster for short to moderately long strings. Isn't any dev interested in fixing this very useful function? It's been such a long time ... I can post my extension code and will attempt to patch the original similar_text() too. Previous Comments: ------------------------------------------------------------------------ [2012-07-24 06:17:33] normadize at gmail dot com Description: ------------ similar_text() returns wrong values, see below for reproducible error. This is actually a very old bug ... would be nice if someone finally fixed it. Test script: --------------- echo similar_text("test","wert"); echo "|"; echo similar_text("wert","test"); Expected result: ---------------- 2|2 Actual result: -------------- 1|2 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=62648&edit=1

« previous php.bugs (#172309) next »