-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Peter Legierski <[email protected]>
- Loading branch information
Peter Legierski
committed
Jul 31, 2014
1 parent
6508559
commit 4a162e9
Showing
1 changed file
with
80 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,83 @@ | ||
htmldiff | ||
======== | ||
|
||
Compare two HTML strings | ||
# Htmldiff | ||
|
||
[](https://travis-ci.org/gathercontent/htmldiff) | ||
|
||
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. | ||
|
||
|
||
## Requirements | ||
|
||
- PHP 5.3.0 or later | ||
- [Tidy](http://php.net/manual/en/intro.tidy.php) extension for PHP | ||
|
||
|
||
## Installation | ||
|
||
Add Htmldiff to your `composer.json` file: | ||
|
||
```json | ||
"require": { | ||
"gathercontent/htmldiff": "0.2.*" | ||
} | ||
``` | ||
|
||
Get composer to install the package: | ||
|
||
```bash | ||
$ composer update gathercontent/htmldiff | ||
``` | ||
|
||
|
||
## Usage | ||
|
||
The input is going to be parsed by Tidy before diffing. Here's a few examples: | ||
|
||
```php | ||
$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> | ||
``` | ||
|
||
```php | ||
$old = '<p>Hello world, how do you do</p>'; | ||
$new = '<p>Hello world, how do <strong>you</strong> do</p>'; | ||
|
||
$htmldiff = new Htmldiff; | ||
$result = $htmldiff->diff($old, $new); | ||
|
||
// result: <p>Hello world, how do <del>you</del><strong><ins>you</ins></strong> do</p> | ||
``` | ||
|
||
```php | ||
$old = '<p>Hello world</p><p>How do you do</p>'; | ||
$new = '<p>Hello world</p><ul><li>first point</li><li>second point</li></ul><p>How do you do</p>'; | ||
|
||
$htmldiff = new Htmldiff; | ||
$result = $htmldiff->diff($old, $new); | ||
|
||
// result: <p>Hello world</p><ul><li><ins>first point</ins></li><li><ins>second point</ins></li></ul><p>How do you do</p> | ||
``` | ||
|
||
## Testing | ||
|
||
Run unit tests: | ||
|
||
``` bash | ||
$ ./vendor/bin/phpunit | ||
``` | ||
|
||
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` | ||
|