2017 © Pedro Peláez
 

library php-diff

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

image

jblond/php-diff

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

  • Tuesday, March 6, 2018
  • by JBlond
  • Repository
  • 6 Watchers
  • 17 Stars
  • 213 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 167 Forks
  • 0 Open issues
  • 3 Versions
  • 16 % Grown

The README.md

PHP Diff Class

Codacy Badge Latest Version Packagist Installs, (*1)

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:, (*2)

  • 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., (*3)

Install

composer require jblond/php-diff

Install for cli support

For cli usage you need to install the suggested jblond/php-cli package., (*4)

Documentation

See the Wiki for, (*5)

Changelog

Changelog, (*6)

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.' : '

' . htmlspecialchars($diff->render($renderer)) . '
' ;

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., (*7)

HTML Side By Side Example

HTML Side By Side Example, (*8)

More Example Pictures
, (*9)

HTML Unified Example

HTML Unified Example, (*10)

Text Unified Example

Text Unified Example, (*11)

Text Context Example

Text Context Example, (*12)

Text Unified Console Example

Text Unified Console Example, (*13)

, (*14)

HTML Side By Side Dark Theme Example
, (*15)

HTML Side By Side Dark Theme Example, (*16)

, (*17)

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, (*18)

You can also fork this repository and open a PR., (*19)

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 ., (*20)

Todo

  • 3 way diff support

Contributors

Contributors since I forked the repo., (*21)

License (BSD License)

see License, (*22)

Tests

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

The Versions

06/03 2018

dev-master

9999999-dev

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

  Sources   Download

BSD-3-Clause

The Requires

  • php >= 5.4
  • ext-mbstring *

 

by Mario

23/01 2018

v1.2

1.2.0.0

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

  Sources   Download

BSD-3-Clause

The Requires

  • php >= 5.4
  • ext-mbstring *

 

by Mario

05/05 2017

v1.1

1.1.0.0

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

  Sources   Download

BSD-3-Clause

The Requires

  • php >= 5.4
  • ext-mbstring *

 

by Mario