jblond / php-diff
这是一个用于生成两个可哈希对象(字符串或数组)之间差异的综合库。
v2.4.0
2021-10-26 18:11 UTC
Requires
- php: >=7.3
- ext-mbstring: *
- ext-pcre: *
Requires (Dev)
- digilive/git-changelog: ^1
- jblond/php-cli: ^1.0
- phpmd/phpmd: 2.*
- phpunit/phpunit: ^8 || ^9
- squizlabs/php_codesniffer: *
Suggests
- jblond/php-cli: ^1.0
This package is auto-updated.
Last update: 2024-08-30 01:43:44 UTC
README
简介
这是一个用于生成两个可哈希对象(字符串或数组)之间差异的综合库。生成的差异可以以所有标准格式呈现,包括
- 统一格式
- 上下文格式
- 并排HTML
- 统一HTML
- 统一命令行彩色输出
- JSON
差异引擎核心(即序列匹配器)的逻辑主要基于Python的difflib包。这样做的主要原因是因为其高精度。
安装
composer require jblond/php-diff
安装以支持命令行
对于命令行使用,您需要安装建议的jblond/php-cli
包。
文档
有关入门、参数和选项、自定义渲染器、样式、变更日志、示例用法和示例输出,请参阅Wiki。
变更日志
示例用法
<?php use jblond\Diff; use jblond\Diff\Renderer\Html\SideBySide; // Installed via composer... require 'vendor/autoload.php'; $sampleA = file_get_contents(dirname(__FILE__).'/a.txt'); $sampleB = file_get_contents(dirname(__FILE__).'/b.txt'); // Options for generating the diff. $options = [ 'ignoreWhitespace' => true, 'ignoreCase' => true, 'context' => 2, 'cliColor' => true, // for cli output 'ignoreLines' => Diff::DIFF_IGNORE_LINE_BLANK, ]; // Initialize the diff class. $diff = new Diff($sampleA, $sampleB /*, $options */); // Choose Renderer. $renderer = new SideBySide([ 'title1' => 'Custom title for sample A', 'title2' => 'Custom title for sample B', ]); // Show the output of the difference renderer. echo $diff->Render($renderer); // Alternative // Show the differences or a message. echo $diff->isIdentical() ? 'No differences found.' : '<pre>' . htmlspecialchars($diff->render($renderer)) . '</pre>' ;
示例输出
文件example.php
包含一个快速演示,可在example/
目录中找到。包括浅色和深色主题。
HTML并排示例
需求
- PHP 7.3或更高版本
- PHP多字节字符串
- jblond/php-cli(建议)
贡献、问题和功能请求
如果您发现了一个错误,或者有关于新功能的想法,请随时在问题跟踪器中报告它——请先进行搜索。问题跟踪器
您也可以fork此存储库并打开一个PR。
使用jQuery合并文件
Xiphe已经构建了一个jQuery插件,您可以使用它来合并比较的文件。请参阅jQuery-Merge-for-php-diff 。
待办事项
- 三路差异支持
贡献者
自从我fork了存储库以来,的贡献者。
许可证(BSD许可证)
请参阅许可证
测试
composer run-script phpunit composer run-script php_src composer run-script php_test