Find level of similarity between strings based on Dice's Coefficient.
Install the package by running
$ composer require aheenam/similar-string
This package contains two classes, one for calculating Dice's Coefficient of two strings and another working with this value.
<?php
use Aheenam\SimilarString\Dice;
(new Dice)('night', 'nacht') // returns 0.25
(new Dice)('abcd', 'abcd') // returns 1
(new Dice)('qwerty', 'asdf') // returns 0
This class provides 2 different methods:
This method orders the strings in $similarStrings
by their Dice-Coefficient when compared to $string
<?php
use Aheenam\SimilarString\SimilarString;
(new SimilarString)->orderBySimilarity('nacht', ['night', 'abcde', 'lacht']);
// returns ['lacht', 'night', 'abcde']
This methods returns the best match for $string
out of $similarStrings
<?php
use Aheenam\SimilarString\SimilarString;
(new SimilarString)->findMostSimilar('nacht', ['night', 'abcde', 'lacht']);
// returns 'lacht'
Check CHANGELOG for the changelog
To run tests use
$ composer test
If you are working on a windows machine use
vendor\bin\phpunit
Information will follow soon
If you discover any security related issues, please email [email protected] or use the issue tracker of GitHub.
Aheenam is a small company from NRW, Germany creating custom digital solutions. Visit our website to find out more about us.
The MIT License (MIT). Please see License File for more information.