Bug #62643 [Opn->Nab]: Wrong percentage similarity
| From: | mike@php.net | Date: | Thu, 05 Dec 2013 17:09:40 +0000 |
| Subject: | Bug #62643 [Opn->Nab]: Wrong percentage similarity | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-183145@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=62643&edit=1
ID: 62643
Updated by: mike@php.net
Reported by: funnyoz at hotmail dot fr
Summary: Wrong percentage similarity
-Status: Open
+Status: Not a bug
Type: Bug
Package: *General Issues
Operating System: Windows
PHP Version: 5.4.5
Block user comment: N
Private report: N
New Comment:
It should probably rather read: "the similarity of string b to string a"
If you need a consistent result, instead of how much of string a is in string b:
$percent = 100*similar_string($a,$b)/max(strlen($a),strlen($b));
Previous Comments:
------------------------------------------------------------------------
[2012-07-23 18:14:33] funnyoz at hotmail dot fr
Description:
------------
If you need the function 'similar_text' to calculate the similarity in percentage between
two strings, the order is important, while it must not be.
(see the Test script for more information)
---
From manual page: http://www.php.net/function.similar-text
---
Test script:
---------------
$var_1 = 'PHP IS GREAT';
$var_2 = 'WITH MYSQL';
similar_text($var_1, $var_2, $percent);
echo $percent;
// 27.272727272727
similar_text($var_2, $var_1, $percent);
echo $percent;
// 18.181818181818
Expected result:
----------------
I expect both the echo's to print :
27.272727272727
Actual result:
--------------
The first echo prints :
27.272727272727
The second :
18.181818181818
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=62643&edit=1