PHPackages                             nochso/diff - 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. nochso/diff

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

nochso/diff
===========

Diff implementation

2.0.0(9y ago)3468[1 issues](https://github.com/nochso/diff/issues)1BSD-3-ClausePHPPHP &gt;=5.6.0

Since Jul 9Pushed 9y ago1 watchersCompare

[ Source](https://github.com/nochso/diff)[ Packagist](https://packagist.org/packages/nochso/diff)[ Docs](https://github.com/nochso/diff)[ RSS](/packages/nochso-diff/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)Dependencies (5)Versions (9)Used By (1)

nochso/diff
===========

[](#nochsodiff)

> Namespace: `\nochso\Diff`

Diff implementation for PHP with support for text, HTML and console output out of the box.

This library is a fork of [sebastian/diff](https://github.com/sebastianbergmann/diff): While the original diff implementation has not notably changed, new features were added:

- Configurable limit for lines of context around the modified lines
- Plain PHP templates for displaying diffs in:
    - Plain text
    - Colored POSIX console output
    - HTML
    - Github flavoured Markdown
- Modify existing templates or create your own
- Line numbering based on the "before" string
- `Upstream` formatter for maintaining compatibility with `sebastian/diff` — and to keep the original tests around

---

- [nochso/diff](#nochsodiff)
- [Installation](#installation)
- [Usage](#usage)

Installation
============

[](#installation)

```
composer require nochso/diff

```

Usage
=====

[](#usage)

Start with creating a `Diff` object by passing two strings to `Diff::create()`:

```
$diff = \nochso\Diff\Diff::create('foo', 'bar');
```

The Diff object contains a list of `DiffLine` objects, consisting of text, a line number and the type of diff operation.

```
foreach ($diff->getDiffLines() as $line) {
    if ($line->isRemoval()) {
        echo 'Line ' . $line->getLineNumberFrom() . " was removed:\n";
        echo $line->getText() . "\n";
    }
}
```

Most of the time you'll want to display the diff somewhere. You can pass a Diff instance to anything that implements the `Formatter` interface:

```
$formatter = new \nochso\Diff\Format\Template\Text();
echo $formatter->format($diff);
```

Output:

```
1: -foo
 : +bar

```

How about two lines of context and Github flavoured Markdown?

```
$context = new ContextDiff();
$context->setMaxContext(2);
$diff = Diff::create($from, $to, $context);
$gfm = new \nochso\Diff\Format\Template\GithubMarkdown();
echo $gfm->format($diff);
```

```
```diff
 2: pariatur ground round
 3: dolore meatloaf nisi
-4: shoulder.
 5: Consequat rump spare
-6: ribs ham hock shank.
 7: Magna esse nisi
 8: frankfurter picanha
```

```

As you can see, when creating a Diff you can pass a ContextDiff object to change the default behaviour.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance13

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 57.5% 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 ~176 days

Recently: every ~163 days

Total

7

Last Release

3635d ago

Major Versions

1.4.1 → 2.0.02016-05-31

PHP version history (2 changes)1.0.0PHP &gt;=5.3.3

2.0.0PHP &gt;=5.6.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6887618?v=4)[Marcel Voigt](/maintainers/nochso)[@nochso](https://github.com/nochso)

---

Top Contributors

[![nochso](https://avatars.githubusercontent.com/u/6887618?v=4)](https://github.com/nochso "nochso (88 commits)")[![sebastianbergmann](https://avatars.githubusercontent.com/u/25218?v=4)](https://github.com/sebastianbergmann "sebastianbergmann (44 commits)")[![whatthejeff](https://avatars.githubusercontent.com/u/306525?v=4)](https://github.com/whatthejeff "whatthejeff (7 commits)")[![nafigator](https://avatars.githubusercontent.com/u/1971423?v=4)](https://github.com/nafigator "nafigator (3 commits)")[![GrahamCampbell](https://avatars.githubusercontent.com/u/2829600?v=4)](https://github.com/GrahamCampbell "GrahamCampbell (3 commits)")[![djmattyg007](https://avatars.githubusercontent.com/u/489338?v=4)](https://github.com/djmattyg007 "djmattyg007 (3 commits)")[![pscheit](https://avatars.githubusercontent.com/u/488189?v=4)](https://github.com/pscheit "pscheit (2 commits)")[![mimrock](https://avatars.githubusercontent.com/u/779206?v=4)](https://github.com/mimrock "mimrock (1 commits)")[![keradus](https://avatars.githubusercontent.com/u/2716794?v=4)](https://github.com/keradus "keradus (1 commits)")[![henriquemoody](https://avatars.githubusercontent.com/u/154023?v=4)](https://github.com/henriquemoody "henriquemoody (1 commits)")

---

Tags

difflcs

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/nochso-diff/health.svg)

```
[![Health](https://phpackages.com/badges/nochso-diff/health.svg)](https://phpackages.com/packages/nochso-diff)
```

###  Alternatives

[jfcherng/php-diff

A comprehensive library for generating differences between two strings in multiple formats (unified, side by side HTML etc).

4705.1M51](/packages/jfcherng-php-diff)[caxy/php-htmldiff

A library for comparing two HTML files/snippets and highlighting the differences using simple HTML.

21520.9M15](/packages/caxy-php-htmldiff)[localheinz/diff

Fork of sebastian/diff for use with ergebnis/composer-normalize

4637.0M5](/packages/localheinz-diff)[mkalkbrenner/php-htmldiff-advanced

An add-on for the php-htmldiff library for comparing two HTML files/snippets and highlighting the differences using simple HTML.

3517.8M1](/packages/mkalkbrenner-php-htmldiff-advanced)[jbzoo/composer-diff

See what has changed after a composer update.

53888.9k1](/packages/jbzoo-composer-diff)[lolli42/finediff

PHP implementation of a Fine granularity Diff engine

138.8M3](/packages/lolli42-finediff)

PHPackages © 2026

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