ssddanbrown/htmldiff
Composer 安装命令:
composer require ssddanbrown/htmldiff
包简介
HTML Content Diff Generator
README 文档
README
This library will compare two provided HTML string inputs and output HTML, tagged with the differences between the two.
This is a PHP port of the c# implementation found here which is a port of the ruby implementation found here. Major credit to @Rohland and @myobie for their original work which I have just simply translated to PHP.
Installation
You can install the package via composer:
composer require ssddanbrown/htmldiff
Usage
The library provides a direct static function to quickly create a HTML diff:
$diff = Ssddanbrown\HtmlDiff\Diff::excecute('<p>Hello there!</p>', '<p>Hi there!</p>'); // $diff = '<p><del class="diffmod">Hello</del><ins class="diffmod">Hi</ins> there!</p>';
Alternatively, You can instead create an instance of the Diff class to configure a few options first:
use Ssddanbrown\HtmlDiff\Diff; $diff = new Diff('<p>Hello there!</p>', '<p>Hi there!</p>'); $diff->repeatingWordsAccuracy = 1; $diff->ignoreWhitespaceDifferences = false; $diff->orphanMatchThreshold = 0.2; $output = $diff->build();
Options
$diff->repeatingWordsAccuracy
Number, Defaults to 1. Valid values are from 0 to 1.
Defines how to compare repeating words. This value allows to exclude some words from comparison that eventually reduces the total time of the diff algorithm. 0 means that all words are excluded so the diff will not find any matching words at all. 1 (default value) means that all words participate in comparison so this is the most accurate case. 0.5 means that any word that occurs more than 50% times may be excluded from comparison. This doesn't mean that such words will definitely be excluded but only gives a permission to exclude them if necessary.
$diff->ignoreWhitespaceDifferences
Boolean value. Defaults to true.
If set to true all whitespace characters, including , are treated as being equal.
$diff->orphanMatchThreshold
Number, Defaults to 0. Valid values are from 0 to 1.
If some match is too small and located far from its neighbors then it is considered as orphan and removed. This property defines relative size of the match to be considered as orphan, from 0 to 1. 1 means that all matches will be considered as orphans. 0 (default) means that no match will be considered as orphan. 0.2 means that if match length is less than 20% of distance between its neighbors it is considered as orphan.
$diff->addBlockExpression($expression)
Add a regular expression that will be used to 'group' text together so that it's treated as a single block.
The $expression passed to the method must be a valid PHP regex pattern string.
Development
This package is built to very closely follow the code and structure of the c# library that it was originally ported from. It will remain closely aligned for this original release but may deviate in the future.
Psalm is included for static analysis. It can be run like so:
./vendor/bin/psalm
PHPUnit is used for testing. It can be run like so:
./vendor/bin/phpunit
License
This project, and the projects that this library has been ported from, is licensed under the MIT License. See the license file for more info.
ssddanbrown/htmldiff 适用场景与选型建议
ssddanbrown/htmldiff 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 628.14k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 11 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 ssddanbrown/htmldiff 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ssddanbrown/htmldiff 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 628.14k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 29
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-11-29