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

Reply via email to