Htmldiff
, (*1)
Compare two HTML strings. This library converts HTML into a form that can be diffed using the algorithm found in Git or Linux (comparing entire lines of code) to achieve greater accuracy, then decodes it back into a valid HTML., (*2)
Requirements
- PHP 5.3.0 or later
-
Tidy extension for PHP
Installation
Add Htmldiff to your composer.json
file:, (*3)
"require": {
"gathercontent/htmldiff": "0.2.*"
}
Get composer to install the package:, (*4)
$ composer update gathercontent/htmldiff
Usage
The input is going to be parsed by Tidy before diffing. Here's a few examples:, (*5)
$old = '<span>This is a string</span>';
$new = '<span>This is a text</span>';
$htmldiff = new Htmldiff;
$result = $htmldiff->diff($old, $new);
// result: <span>This is a <del>string</del><ins>text</ins></span>
$old = '
Hello world, how do you do, (*6)
';
$new = '
Hello world, how do you do, (*7)
';
$htmldiff = new Htmldiff;
$result = $htmldiff->diff($old, $new);
// result:
Hello world, how do youyou do, (*8)
$old = '
Hello world, (*9)
How do you do, (*10)
';
$new = '
Hello world, (*11)
How do you do, (*12)
';
$htmldiff = new Htmldiff;
$result = $htmldiff->diff($old, $new);
// result:
Hello world, (*13)
How do you do, (*14)
Testing
Run unit tests:, (*15)
``` bash
$ ./vendor/bin/phpunit, (*16)
Test compliance with [PSR2 coding style guide](http://www.php-fig.org/psr/psr-2/):
``` bash
$ ./vendor/bin/phpcs --standard=PSR2 ./src
Licence
The MIT License (MIT) - see README.md
, (*17)