承接 jblond/php-diff 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jblond/php-diff

最新稳定版本:2.5.0

Composer 安装命令:

composer require jblond/php-diff

包简介

A comprehensive library for generating differences between two hashable objects (strings or arrays).

README 文档

README

Codacy Badge Latest Version Packagist Installs

Introduction

A comprehensive library for generating differences between two hashable objects (strings or arrays). Generated differences can be rendered in all the standard formats including:

  • Unified
  • Context
  • Side by Side HTML
  • Unified HTML
  • Unified Commandline colored output
  • JSON

The logic behind the core of the diff engine (ie, the sequence matcher) is primarily based on the Python difflib package. The reason for doing so is primarily because of its high degree of accuracy.

Install

composer require jblond/php-diff

Install for cli support

For cli usage you need to install the suggested jblond/php-cli package.

Documentation

See the Wiki for

Changelog

Changelog

Example Use

<?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 Output

File example.php contains a quick demo and can be found in the example/ directory. Included is a light and a dark theme.

HTML Side By Side Example

HTML Side By Side Example

More Example Pictures

HTML Unified Example

HTML Unified Example

Text Unified Example

Text Unified Example

Text Context Example

Text Context Example

Text Unified Console Example

Text Unified Console Example

HTML Side By Side Dark Theme Example

HTML Side By Side Dark Theme Example

Requirements

Contribution, Issues and feature requests

If you found a bug, or have an idea for new functionality, feel free to report it on the issue tracker - just use search beforehand. Issue tracker

You can also fork this repository and open a PR.

Merge files using jQuery

Xiphe has build a jQuery plugin with that you can merge the compared files. Have a look at jQuery-Merge-for-php-diff .

Todo

  • 3 way diff support

Contributors

Contributors since I forked the repo.

License (BSD License)

see License

Tests

composer run-script phpunit composer run-script php_src composer run-script php_test

统计信息

  • 总下载量: 119.21k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 36
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 36
  • Watchers: 5
  • Forks: 191
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固