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

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

jfcherng/php-diff
=================

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

6.16.2(2y ago)4705.1M—2.7%51[2 issues](https://github.com/jfcherng/php-diff/issues)[1 PRs](https://github.com/jfcherng/php-diff/pulls)20BSD-3-ClausePHPPHP &gt;=7.4CI failing

Since Jun 24Pushed 5mo ago9 watchersCompare

[ Source](https://github.com/jfcherng/php-diff)[ Packagist](https://packagist.org/packages/jfcherng/php-diff)[ Fund](https://www.paypal.me/jfcherng/5usd)[ RSS](/packages/jfcherng-php-diff/feed)WikiDiscussions v6 Synced 1mo ago

READMEChangelog (10)Dependencies (8)Versions (154)Used By (20)

php-diff
========

[](#php-diff)

[![GitHub Workflow Status (branch)](https://camo.githubusercontent.com/cb54027554a89393f46b1c2d6c5125188e3c69dc3a704edc1989375c6de2aec0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6a66636865726e672f7068702d646966662f7068702e796d6c3f6272616e63683d7636267374796c653d666c61742d737175617265)](https://github.com/jfcherng/php-diff/actions)[![Codacy grade](https://camo.githubusercontent.com/d989219130927c179e0ae2168f5e209c0716ed0eaf23d423d53a30e69ea4a538/68747470733a2f2f696d672e736869656c64732e696f2f636f646163792f67726164652f35623761623565643631336434386239396631326364333334663634383966662f76363f7374796c653d666c61742d737175617265)](https://app.codacy.com/project/jfcherng/php-diff/dashboard)[![Packagist](https://camo.githubusercontent.com/2e594d7be0133d3a7dc6095741a41746647c31c838888bbd7b5cd874c456341d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a66636865726e672f7068702d646966663f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jfcherng/php-diff)[![Packagist Version](https://camo.githubusercontent.com/ffcbde4e6ebe115ee1010444a4ee5f6333a68ba19277fe206516b50935ac49e3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a66636865726e672f7068702d646966663f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jfcherng/php-diff)[![Project license](https://camo.githubusercontent.com/67412fd57703776b8f0b9590043bb475290cf4f6e79dc8cc3add66ec7441402d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6a66636865726e672f7068702d646966663f7374796c653d666c61742d737175617265)](https://github.com/jfcherng/php-diff/blob/v6/LICENSE)[![GitHub stars](https://camo.githubusercontent.com/efa62246fe47457406dcecaac5c216c7e3fa3e8a4db0ac5c56b1366c024f4304/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f6a66636865726e672f7068702d646966663f7374796c653d666c61742d737175617265266c6f676f3d676974687562)](https://github.com/jfcherng/php-diff/stargazers)[![Donate to this project using Paypal](https://camo.githubusercontent.com/b3f28a26023aadc92afb98cdbcec5f66ed5b471222cf2af28454b871d93372f4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f70617970616c2d646f6e6174652d626c75652e7376673f7374796c653d666c61742d737175617265266c6f676f3d70617970616c)](https://www.paypal.me/jfcherng/5usd)

A comprehensive library for generating diff between two strings.

Introduction
------------

[](#introduction)

Generated diff can be rendered in all of the standard formats including:

**Text** renderers:

- Context
- Json (plain text)
- Unified

**HTML** renderers:

- Combined
- Inline
- Json (HTML)
- Side by Side

Note that for HTML rendered results, you have to add CSS for a better visualization. You may modify one from `example/diff-table.css` or write your own from zero.

If you are okay with the default CSS, there is `\Jfcherng\Diff\DiffHelper::getStyleSheet()`which can be used to get the content of the `example/diff-table.css`.

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

[](#requirements)

[![php](https://camo.githubusercontent.com/8981c64d351803a750026885c8947656d0ece473ff79eeb27d7d357b7c418e80/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d254532253839254135372e342e302d626c75653f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/8981c64d351803a750026885c8947656d0ece473ff79eeb27d7d357b7c418e80/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d254532253839254135372e342e302d626c75653f7374796c653d666c61742d737175617265)[![ext-iconv](https://camo.githubusercontent.com/9b62dc2b788d4a71cbbcf8abdfac07be8d19a76f19394e4c1dce5551a827b49f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6578742d69636f6e762d627269676874677265656e3f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/9b62dc2b788d4a71cbbcf8abdfac07be8d19a76f19394e4c1dce5551a827b49f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6578742d69636f6e762d627269676874677265656e3f7374796c653d666c61742d737175617265)

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

[](#installation)

This package is available on `Packagist` by the name of [jfcherng/php-diff](https://packagist.org/packages/jfcherng/php-diff).

```
composer require jfcherng/php-diff
```

Example
-------

[](#example)

See files and readme in the [example/](https://github.com/jfcherng/php-diff/blob/v6/example) directory.

```
