php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62643 Wrong percentage similarity
Submitted: 2012-07-23 18:14 UTC Modified: 2013-12-05 17:09 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: funnyoz at hotmail dot fr Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.4.5 OS: Windows
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: funnyoz at hotmail dot fr
New email:
PHP Version: OS:

 

 [2012-07-23 18:14 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-12-05 17:09 UTC] mike@php.net
-Status: Open +Status: Not a bug
 [2013-12-05 17:09 UTC] mike@php.net
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));
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Jul 04 20:01:35 2025 UTC