PHPackages                             manuwhat/similar-text - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. manuwhat/similar-text

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

manuwhat/similar-text
=====================

Similar-text - Compare two strings to compute a similarity score

13.4k↓50%3PHP

Since Apr 29Pushed 7y ago1 watchersCompare

[ Source](https://github.com/manuwhat/similar-text)[ Packagist](https://packagist.org/packages/manuwhat/similar-text)[ RSS](/packages/manuwhat-similar-text/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (3)Used By (0)

PHP Similar Text Percentage: Compare two strings to compute a similarity score
==============================================================================

[](#php-similar-text-percentage-compare-two-strings-to-compute-a-similarity-score)

[![Build Status](https://camo.githubusercontent.com/89c968235e625d01087ba8e3832c167da9a16557fe73def7f7a2f06288773d30/68747470733a2f2f7472617669732d63692e6f72672f6d616e75776861742f73696d696c61722d746578742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/manuwhat/similar-text)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/456b17f1ee7380d389ab1d3e2425f2f2abc7ee39e3f6c04daccb5fa2359c2897/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d616e75776861742f73696d696c61722d746578742f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/manuwhat/similar-text/?branch=master)[![Build Status](https://camo.githubusercontent.com/8dcf0783e9b2b756b9f5016ef6f40a8987ab8f79fe5c9b773d5579cf0c43a886/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d616e75776861742f73696d696c61722d746578742f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/manuwhat/similar-text/build-status/master)[![Code Intelligence Status](https://camo.githubusercontent.com/2a4493abd92c3a29852831a8b4b848f88d4bc545f362f88152bee058067089d4/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d616e75776861742f73696d696c61722d746578742f6261646765732f636f64652d696e74656c6c6967656e63652e7376673f623d6d6173746572)](https://scrutinizer-ci.com/code-intelligence)

### Library which help to Compare two strings to compute a similarity score and get stats on how linked are the strings.

[](#library-which-help-to-compare-two-strings-to-compute-a-similarity-score-and-get-stats-on-how-linked-are-the-strings)

**Requires**: PHP 5.3+

### What this library exactly does?

[](#what-this-library-exactly-does)

this library can compare two strings to compute a similarity score.

It takes the text of two strings and analyze them using pure PHP code to evaluate how equal they are.

The class returns a number that represents a percentage of the two strings to tell the level of similarity.

Based on the stats provided It actually can help to detect similarity even if these cases occurred : WORD REORDER,WHITESPACE AND PUNCTUATION,REMOVE WORDS,ADD WORDS,URL STRIPPING, FORM ACRONYM,EXPAND ACRONYM,STEMMING,SUBSTRING ,SUPERSTRING,ABBREVIATION ,ANAGRAM

### How to use it

[](#how-to-use-it)

Require the library by issuing this command:

```
composer require manuwhat/similar-text
```

Add `require 'vendor/autoload.php';` to the top of your script.

Next, use it in your script, just like this:

```
use ezama/similar-text;

100.0===similarText('qwerty', 'ytrewq')
```

This is an example of how to use the stats to check a special case.Here we will use them to check about anagrams (note that this has already been implemented in the library check the file similar\_text.php to know more about all available implementations)

```
function areAnagrams($a, $b)
{
	return  Ezama\similar_text::similarText($a, $b, 2, true, $check)?$check['similar'] === 100.0&&$check['contain']===true:false;
}

areAnagrams('qwerty', 'ytrewq');// return true;
```

Nb: some functions and methods are more subtle than one can think. For example the method simpleCommonTextSimilarities::aIsSuperStringOfB and its helper aIsSuperStringOfB are not at all equal to the usual checking functions built on top of preg\_match ,stripos and PHP similar functions

a simple example is :

```
function aisSuperStringOfB_stripos($a, $b)
{
	return  false!==stripos($a,$b);
}

function aisSuperStringOfB_PCRE($a, $b)
{
	return  preg_match('#'.preg_quote($b).'#i',$a);
}

require './vendor/manuwhat/similar-text/similar_text.php';

aIsSuperStringOfB('mum do you want to cook something', 'do you cook something mum');//return true;
aIsSuperStringOfB_stripos('mum do you want to cook something', 'do you cook something mum');//false;
aIsSuperStringOfB_PCRE('mum do you want to cook something', 'do you cook something mum');//return false;
```

The library also contains common distance algorithms such unlimited string length levenshtein ,levenshtein-damerau ,jaro ,jaro-winkler ,hamming ,dice implementation

### How To run unit tests

[](#how-to-run-unit-tests)

```
phpunit  ./tests
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 85.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/06f6de07cb99fb97189e3607288a40110ad055335e15fd5633c98751b78b6211?d=identicon)[manuwhat](/maintainers/manuwhat)

---

Top Contributors

[![manuwhat](https://avatars.githubusercontent.com/u/29569475?v=4)](https://github.com/manuwhat "manuwhat (40 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (7 commits)")

### Embed Badge

![Health badge](/badges/manuwhat-similar-text/health.svg)

```
[![Health](https://phpackages.com/badges/manuwhat-similar-text/health.svg)](https://phpackages.com/packages/manuwhat-similar-text)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
