Daisy Diff is a PHP implementation of the Java library that diffs (compares) HTML files. It highlights added and removed words and annotates changes to the styling.
You can add this library as a local, per-project dependency to your project using Composer:
composer require snebes/php-daisydiff
The DaisyDiff
class can be used to generate a textual representation of the difference between two HTML strings:
<?php
use SN\DaisyDiff\DaisyDiff;
$original = '<html><body>The original document</body></html>';
$modified = '<html><body>The changed document</body></html>';
$daisyDiff = new DaisyDiff();
\printf("%s\n", $daisyDiff->diff($original, $modified));
The code above yields the output below:
<html>The <del class="diff-html-removed">original </del><ins class="diff-html-added">changed </ins>document</html>
Many thanks to:
- Java DaisyDiff, the original Java version of the DaisyDiff library.
- gdevanla/assist from which many of the tests of this library are extracted.