icap/html-diff
Composer 安装命令:
composer require icap/html-diff
包简介
A PHP5 library that diffs (compares) HTML files.
关键字:
README 文档
README
A PHP5 library that diffs (compares) HTML files.
This library is actually a transfer of the daisy-diff library for PHP, found here for gitgub, meeting the PSR-4 standards. The library was developped in 2008 and is used today by many wiki platforms (wikipedia, wikihub, gamepedia, etc). It is part of code of the MediaWiki package.
Setup
Requirements
- PHP >=5.3.0
- Pimple 1.0.*
- Silex 1.0.*
Installation
The easiest way to install HtmlDiff is using Composer with the following requirement:
{
"require": {
...
"icap/html-diff": ">=1.0.1"
}
}
Alternatively, you can download the archive and add the src/ folder to PHP's include path:
set_include_path('/path/to/src' . PATH_SEPARATOR . get_include_path());
Usage
To find and render the differences between two html blocks html you need include the HtmlDiff class
use Icap\HtmlDiff\HtmlDiff;
and then initialize a new HtmlDiff class object with the following attributes:
- the old html text/block (String)
- the new html text/block (String)
- the option to enable or not formatting changes (Boolean) (set this to true if beside the adds and removes you also want to display the different style modifications of the nodes/elements)
Then call the outputDiff function of the class to retrieve the result with the compared version and the modifications.
$htmlDiff = new HtmlDiff($oldText, $newText, true); $out = $htmlDiff->outputDiff(); //Then $out->toString();//to get the compared version //And $out->getModifications();//to retrieve the number of differences/modifications between the two blocks.
The output is a ChangeText
You can always refer to the demo/examples for further help. In the given examples we use two different styles to render the compared html result. Feel free to copy and use these styles in your application.
Modifications compared to the original library
- In the ChangeText object a new attribute was added (modifications) to count the differences found between the two texts. These differences are given in a form of an array ('added' => #, 'changed' => #, 'removed' => #)
- The details tooltip was removed
- All the MediaWiki general functions (which are defined here) used by the HtmlDiff module, were replaced with some simple/dummy ones so as the module runs without them.
- In the converted html output all the 'added' and 'deleted' span tags were replaced by 'ins' and 'del' tags respectively for WAI compliance reasons.
Tests
Since the library is a tranfer of an already tested (hopefully) library, no tests were created or executed.
Known issues
There is a known issue with table comparison reported here Thow it is referring to the java version of the library, the same issue exists in the PHP version.
icap/html-diff 适用场景与选型建议
icap/html-diff 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 120.07k 次下载、GitHub Stars 达 30, 最近一次更新时间为 2013 年 10 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「html diff」 「daisy diff」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 icap/html-diff 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 icap/html-diff 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 icap/html-diff 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Texy converts plain text in easy to read Texy syntax into structurally valid (X)HTML. It supports adding of images, links, nested lists, tables and has full support for CSS. Texy supports hyphenation of long words (which reflects language rules), clickable emails and URL (emails are obfuscated again
A library for comparing two HTML files/snippets and highlighting the differences using simple HTML.
Schema Diff: Show difference between MySQL databases
HTML and form generation
Lazy UI is a Laravel package that provides a set of Blade components to rapidly build forms with Tailwind CSS and Daisy UI.
统计信息
- 总下载量: 120.07k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 31
- 点击次数: 17
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2013-10-17