ofmadsen / php-differ
Creates diff between two strings, lines or words
0.1.0
2018-11-04 12:25 UTC
Requires
- php: ^7.1
Requires (Dev)
- phpunit/phpunit: ^7.4.3
This package is not auto-updated.
Last update: 2025-02-05 09:26:21 UTC
README
Library for creating diff between two strings, lines or words. It was created as a learning experience for myself, and published as it may be usable for others.
Installation
Install the latest version with:
$ composer require ofmadsen/php-differ
Algorithms
Madsen\Diff\Algorithm\Myers
, described in Eugene W. Myers' 1986 paper.
Usage
$algorithm = new Madsen\Diff\Algorithm\Myers(); $differ = new Madsen\Diff\Differ($algorithm); // $a and $b are strings $diff = $differ->diffLines($a, $b); // Also support ::diffWords() // $diff is Madsen\Diff\Diff that can be iterated: foreach ($diff as $chunk) { // $chunk is an Madsen\Diff\Chunk\AbstractChunk object; AddedChunk, RemovedChunk or UnchangedChunk $content = $chunk->getContent(); } $added = $diff->countAdded(); // Get the number of added chunks $removed = $diff->countRemoved(); // Get the number of removed chunks $unchanged = $diff->countUnchanged(); // Get the number of unchanged chunks
Contribution
All are welcome to contribute to PHP Differ. Please get in touch before making large features and/or major refactoring. Needlessly to say the coding style must be followed and full test coverage is required.
License
PHP Differ is available under the MIT License - see the LICENSE
file for details.