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

From: Date: Wed, 05 Sep 2012 06:11:04 +0000
Subject: Bug #62648 [Com]: similar_text() returns wrong values
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-173184@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 Comment by: carloschilazo 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: the only thing that I'd want to clear out first about this, is the performance of your algorithm vs the built-in function. Could you please provide the test case you are using to measure this? Thanks! Previous Comments: ------------------------------------------------------------------------ [2012-07-29 05:48:14] normadize at gmail dot com 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. ------------------------------------------------------------------------ [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 (#173184) next »