ofmadsen/php-differ

创建两个字符串、行或单词之间的差异

0.1.0 2018-11-04 12:25 UTC

This package is not auto-updated.

Last update: 2024-09-18 07:54:36 UTC


README

一个用于创建两个字符串、行或单词之间差异的库。它是作为我的学习经历而创建的,并发布出来,可能对其他人也有用。

Build Status

安装

使用以下命令安装最新版本:

$ composer require ofmadsen/php-differ

算法

  • Madsen\Diff\Algorithm\Myers,由 Eugene W. Myers 在 1986 年的 论文 中描述。

用法

$algorithm = new Madsen\Diff\Algorithm\Myers();
$differ = new Madsen\Diff\Differ($algorithm);

// $a and $b are strings
$diff = $differ->diffLines($a, $b); // Also support ::diffWords()

// $diff is Madsen\Diff\Diff that can be iterated:
foreach ($diff as $chunk) {
    // $chunk is an Madsen\Diff\Chunk\AbstractChunk object; AddedChunk, RemovedChunk or UnchangedChunk
    $content = $chunk->getContent();
}

$added = $diff->countAdded(); // Get the number of added chunks
$removed = $diff->countRemoved(); // Get the number of removed chunks
$unchanged = $diff->countUnchanged(); // Get the number of unchanged chunks

贡献

所有人均欢迎为 PHP Differ 做出贡献。在做出大型功能或重大重构之前,请先与我们联系。不用说,必须遵循编码风格,并需要完整的测试覆盖率。

许可

PHP Differ 可在 MIT 许可证下使用 - 详细信息请参阅 LICENSE 文件。