PHPackages                             oefenweb/damerau-levenshtein - 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. oefenweb/damerau-levenshtein

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

oefenweb/damerau-levenshtein
============================

Get text similarity level with Damerau-Levenshtein distance

v3.0.2(4y ago)40265.8k↓26.6%10[1 PRs](https://github.com/Oefenweb/damerau-levenshtein/pulls)4MITPHPPHP &gt;=7.1.0CI failing

Since Oct 22Pushed 4y ago5 watchersCompare

[ Source](https://github.com/Oefenweb/damerau-levenshtein)[ Packagist](https://packagist.org/packages/oefenweb/damerau-levenshtein)[ Docs](http://github.com/Oefenweb/damerau-levenshtein)[ RSS](/packages/oefenweb-damerau-levenshtein/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (15)Used By (4)

Damerau Levenshtein
===================

[](#damerau-levenshtein)

[![CI](https://github.com/Oefenweb/damerau-levenshtein/workflows/CI/badge.svg)](https://github.com/Oefenweb/damerau-levenshtein/actions?query=workflow%3ACI)[![PHP 7 ready](https://camo.githubusercontent.com/bcea3691ba59923341f2469a5a20893485fc89d994288458c5dbffcfe6b4de0f/687474703a2f2f7068703772656164792e74696d6573706c696e7465722e63682f4f6566656e7765622f64616d657261752d6c6576656e73687465696e2f62616467652e737667)](https://travis-ci.org/Oefenweb/damerau-levenshtein)[![codecov](https://camo.githubusercontent.com/6921b284d0cc362128327a062f4dd69015f55dc8871b45b364f0552931681974/68747470733a2f2f636f6465636f762e696f2f67682f4f6566656e7765622f64616d657261752d6c6576656e73687465696e2f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/Oefenweb/damerau-levenshtein)[![Packagist downloads](https://camo.githubusercontent.com/f9605d3ba837a7fc338955b0eed97af84629dc23d41dbde3b81006c40ac4a46e/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f4f6566656e7765622f64616d657261752d6c6576656e73687465696e2e737667)](https://packagist.org/packages/oefenweb/damerau-levenshtein)[![Code Climate](https://camo.githubusercontent.com/8a61a17e6fe3b00ddbc966e2007a906f50afd658b795a9a69499d6b754a6561b/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f4f6566656e7765622f64616d657261752d6c6576656e73687465696e2f6261646765732f6770612e737667)](https://codeclimate.com/github/Oefenweb/damerau-levenshtein)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/5d2b6a6b9948728c6f79210c81e963a5fcf0926ba27b4ad9f64f4fa45b15418f/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4f6566656e7765622f64616d657261752d6c6576656e73687465696e2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Oefenweb/damerau-levenshtein/?branch=master)

Get text similarity level with Damerau-Levenshtein distance.

Requirements
------------

[](#requirements)

- PHP 7.1.0 or greater.

Installation
------------

[](#installation)

`composer require oefenweb/damerau-levenshtein`

Usage
-----

[](#usage)

```
$pattern = 'foo bar';
$string  = 'fuu baz';

$damerauLevenshtein = new DamerauLevenshtein($pattern, $string);

$damerauLevenshtein->getSimilarity(); // absolute edit distance; == 3

$damerauLevenshtein->getRelativeDistance(); // relative edit distance; == 0.57142857142857

$damerauLevenshtein->getMatrix(); // get complete distance matrix
/* ==
 * [
 *   [0,1,2,3,4,5,6,7],
 *   [1,0,1,2,3,4,5,6],
 *   [2,1,1,2,3,4,5,6],
 *   [3,2,2,2,3,4,5,6],
 *   [4,3,3,3,2,3,4,5],
 *   [5,4,4,4,3,2,3,4],
 *   [6,5,5,5,4,3,2,3],
 *   [7,6,6,6,5,4,3,3],
 * ]
 */

$damerauLevenshtein->displayMatrix(); // get readable and formatted distance matrix
/*
 *   '  foo bar' . PHP_EOL
 * . ' 01234567' . PHP_EOL
 * . 'f10123456' . PHP_EOL
 * . 'u21123456' . PHP_EOL
 * . 'u32223456' . PHP_EOL
 * . ' 43332345' . PHP_EOL
 * . 'b54443234' . PHP_EOL
 * . 'a65554323' . PHP_EOL
 * . 'z76665433'
 */
```

Different costs are supported by the constructor and getters / setters.

Character comparison (equal check) can easily be overridden by parent class (see `DamerauLevenshtein::compare`).

For more examples look at `/tests/DamerauLevenshteinTest.php` or **RTFC**.

License
-------

[](#license)

MIT

#### Author Information

[](#author-information)

Mischa ter Smitten (based on work of [Ph4r05](http://www.phpclasses.org/package/7021-PHP-Get-text-similarity-level-with-Damerau-Levenshtein.html))

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity47

Moderate usage in the ecosystem

Community20

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 95.3% 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.

###  Release Activity

Cadence

Every ~208 days

Recently: every ~288 days

Total

14

Last Release

1518d ago

Major Versions

v1.0.2 → v2.0.02015-06-09

v2.1.5 → v3.0.02019-01-23

PHP version history (4 changes)v1.0.0PHP &gt;=5.3.10

v2.1.0PHP &gt;=5.4.16

v3.0.0PHP &gt;=7.0.0

v3.0.1PHP &gt;=7.1.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/8408dd4d7c016002e99aa4bdb978519a5a1966ce14f7afc90b5830dbe864500a?d=identicon)[oefenweb](/maintainers/oefenweb)

---

Top Contributors

[![tersmitten](https://avatars.githubusercontent.com/u/3392962?v=4)](https://github.com/tersmitten "tersmitten (82 commits)")[![mvdriel](https://avatars.githubusercontent.com/u/408052?v=4)](https://github.com/mvdriel "mvdriel (4 commits)")

---

Tags

damerau-levenshteinphptextdistancesimilaritylevenshteindamerau

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/oefenweb-damerau-levenshtein/health.svg)

```
[![Health](https://phpackages.com/badges/oefenweb-damerau-levenshtein/health.svg)](https://phpackages.com/packages/oefenweb-damerau-levenshtein)
```

###  Alternatives

[mjaschen/phpgeo

Simple Yet Powerful Geo Library

1.6k8.6M22](/packages/mjaschen-phpgeo)[edgaras/strsim

Collection of string similarity and distance algorithms in PHP including Levenshtein, Damerau-Levenshtein, Jaro-Winkler, and more

2423.0k](/packages/edgaras-strsim)[tga/simhash-php

SimHash similarities algorithm implementation for PHP 5.3

15243.5k1](/packages/tga-simhash-php)[atomescrochus/laravel-string-similarities

Compare two string and get a similarity percentage

70160.1k2](/packages/atomescrochus-laravel-string-similarities)[matthiasmullie/geo

Geography helper

6377.6k1](/packages/matthiasmullie-geo)[ballen/distical

A distance (Lat/Long) calculation library for PHP

40180.2k2](/packages/ballen-distical)

PHPackages © 2026

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