PHPackages                             pecl/xdiff - 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. pecl/xdiff

ActivePhp-ext[Utility &amp; Helpers](/categories/utility)

pecl/xdiff
==========

File differences/patches.

2.2.0(2mo ago)16616PHP-3.01CPHP &gt;=7.0.0CI passing

Since Apr 6Pushed 2mo ago7 watchersCompare

[ Source](https://github.com/php/pecl-text-xdiff)[ Packagist](https://packagist.org/packages/pecl/xdiff)[ RSS](/packages/pecl-xdiff/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (2)DependenciesVersions (2)Used By (0)

xdiff
=====

[](#xdiff)

PHP extension for creating and applying patches to both text and binary files. Wraps the [libxdiff](http://www.xmailserver.org/xdiff-lib.html) library.

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

[](#installation)

### PIE (recommended)

[](#pie-recommended)

```
pie install pecl/xdiff
```

### PECL

[](#pecl)

```
pecl install xdiff
```

### From source

[](#from-source)

Requires libxdiff with `xdl_set_allocator`, `xdl_rabdiff`, and `XDL_PATCH_IGNOREBSPACE` support.

```
phpize
./configure --with-xdiff
make
make install
```

API
---

[](#api)

### Diff

[](#diff)

```
xdiff_string_diff(string $str1, string $str2, int $context = 3, bool $minimal = false): string|false
```

Creates a unified diff of two strings. `$context` sets the number of surrounding lines. `$minimal` reduces diff size at the cost of speed.

```
xdiff_file_diff(string $file1, string $file2, string $dest, int $context = 3, bool $minimal = false): bool
```

Creates a unified diff of two files and writes the result to `$dest`.

```
xdiff_string_diff_binary(string $str1, string $str2): string|false
```

Creates a binary diff of two strings.

```
xdiff_file_diff_binary(string $file1, string $file2, string $dest): bool
```

Creates a binary diff of two files and writes the result to `$dest`.

```
xdiff_string_rabdiff(string $str1, string $str2): string|false
```

Creates a binary diff of two strings using the Rabin fingerprint algorithm.

```
xdiff_file_rabdiff(string $file1, string $file2, string $dest): bool
```

Creates a binary diff of two files using the Rabin fingerprint algorithm and writes the result to `$dest`.

### Patch

[](#patch)

```
xdiff_string_patch(string $file, string $patch, int $flags = XDIFF_PATCH_NORMAL, ?string &$error = null): string|bool
```

Applies a unified patch to a string. Returns the patched string, or `false` on error. Rejected chunks are returned via `$error`.

`$flags`: `XDIFF_PATCH_NORMAL` (default) or `XDIFF_PATCH_REVERSE`.

```
xdiff_file_patch(string $file, string $patch, string $dest, int $flags = XDIFF_PATCH_NORMAL): string|bool
```

Applies a unified patch from a file. Returns `true` on success, a string of rejected chunks on partial failure, or `false` on error.

```
xdiff_string_patch_binary(string $str, string $patch): string|false
```

Applies a binary patch to a string. Works with both bdiff and rabdiff patches.

```
xdiff_file_patch_binary(string $file, string $patch, string $dest): bool
```

Applies a binary patch from a file and writes the result to `$dest`.

### Merge

[](#merge)

```
xdiff_string_merge3(string $str1, string $str2, string $str3, ?string &$error = null): string|bool
```

Three-way merge of strings. Returns the merged string, or `false` on error. Conflicts are returned via `$error`.

```
xdiff_file_merge3(string $file1, string $file2, string $file3, string $dest): string|bool
```

Three-way merge of files. Returns `true` on success, a string of rejected chunks on conflict, or `false` on error.

### Binary diff size

[](#binary-diff-size)

```
xdiff_string_bdiff_size(string $patch): int|false
```

Returns the size of the file that would be created by applying the given binary patch.

```
xdiff_file_bdiff_size(string $patch_file): int|false
```

Same as above, but reads the patch from a file.

Constants
---------

[](#constants)

ConstantDescription`XDIFF_PATCH_NORMAL`Apply patch normally (default)`XDIFF_PATCH_REVERSE`Reverse the patch`XDIFF_PATCH_IGNORESPACE`Ignore whitespace when patching

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance88

Actively maintained with recent releases

Popularity16

Limited adoption so far

Community24

Small or concentrated contributor base

Maturity28

Early-stage or recently created project

 Bus Factor3

3 contributors hold 50%+ of commits

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

Unknown

Total

1

Last Release

64d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/04c4b64e4b0528a79749a79b300ef81c093cbdaeb733b2b2c2a39b4352fa19a3?d=identicon)[rlerdorf](/maintainers/rlerdorf)

---

Top Contributors

[![rlerdorf](https://avatars.githubusercontent.com/u/54641?v=4)](https://github.com/rlerdorf "rlerdorf (14 commits)")[![remicollet](https://avatars.githubusercontent.com/u/270445?v=4)](https://github.com/remicollet "remicollet (13 commits)")[![Sean-Der](https://avatars.githubusercontent.com/u/1302304?v=4)](https://github.com/Sean-Der "Sean-Der (11 commits)")[![cmb69](https://avatars.githubusercontent.com/u/2306138?v=4)](https://github.com/cmb69 "cmb69 (9 commits)")[![felipensp](https://avatars.githubusercontent.com/u/773947?v=4)](https://github.com/felipensp "felipensp (5 commits)")[![helly25](https://avatars.githubusercontent.com/u/6420169?v=4)](https://github.com/helly25 "helly25 (3 commits)")[![ranvis](https://avatars.githubusercontent.com/u/139048?v=4)](https://github.com/ranvis "ranvis (2 commits)")[![wez](https://avatars.githubusercontent.com/u/117777?v=4)](https://github.com/wez "wez (2 commits)")[![plstand](https://avatars.githubusercontent.com/u/762731?v=4)](https://github.com/plstand "plstand (2 commits)")[![shivammathur](https://avatars.githubusercontent.com/u/1571086?v=4)](https://github.com/shivammathur "shivammathur (2 commits)")[![jparise](https://avatars.githubusercontent.com/u/10311?v=4)](https://github.com/jparise "jparise (1 commits)")[![tony2001](https://avatars.githubusercontent.com/u/42386?v=4)](https://github.com/tony2001 "tony2001 (1 commits)")[![weltling](https://avatars.githubusercontent.com/u/22016?v=4)](https://github.com/weltling "weltling (1 commits)")[![johannes](https://avatars.githubusercontent.com/u/44364?v=4)](https://github.com/johannes "johannes (1 commits)")

### Embed Badge

![Health badge](/badges/pecl-xdiff/health.svg)

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

###  Alternatives

[humanmade/foundry

Foundry is an experimental approach to custom tables in WordPress.

151.1k3](/packages/humanmade-foundry)

PHPackages © 2026

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