gathercontent / htmldiff
比较两个HTML字符串
0.2.1
2015-04-15 15:39 UTC
Requires
- ext-tidy: *
- cogpowered/finediff: 0.3.1
Requires (Dev)
- phpunit/phpunit: 4.*
- squizlabs/php_codesniffer: 1.*
This package is not auto-updated.
Last update: 2024-09-24 02:32:41 UTC
README
比较两个HTML字符串。此库将HTML转换为可以使用Git或Linux中的算法(比较整行代码)进行diff的形式,以实现更高的准确性,然后再将其解码回有效的HTML。
要求
- PHP 5.3.0或更高版本
- Tidy扩展包
安装
将Htmldiff添加到您的composer.json
文件中
"require": { "gathercontent/htmldiff": "0.2.*" }
让composer安装包
$ composer update gathercontent/htmldiff
用法
输入将在diff之前由Tidy解析。以下是一些示例
$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 = '<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>
$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>
测试
运行单元测试
$ ./vendor/bin/phpunit
测试是否符合PSR2编码风格指南
$ ./vendor/bin/phpcs --standard=PSR2 ./src
许可证
MIT许可证(MIT) - 请参阅README.md