Giter Club home page Giter Club logo

php-diff's Introduction

PHP Diff Class

Introduction

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

  • Unified
  • Context
  • Inline HTML
  • Side by Side HTML

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.

Example Use

A quick usage example can be found in the example/ directory and under example.php.

More complete documentation will be available shortly.

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

  • Ability to ignore blank line changes
  • 3 way diff support
  • Performance optimizations

License (BSD License)

Copyright (c) 2009 Chris Boulton [email protected] All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  • Neither the name of the Chris Boulton nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
POSSIBILITY OF SUCH DAMAGE.

php-diff's People

Contributors

chrisboulton avatar dgarrett avatar jensklose avatar joec4i avatar joshfraser avatar kelunik avatar xiphe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

php-diff's Issues

Fix for a small line numbering error.

Small library very useful for me. Thank's a lot !

Line 129 of the file lib/Dif/Renderer/Html/SideBySide.php should be corrected like this:
$toLine = $change['base']['offset'] + $no + 1; -> $toLine = $change['changed']['offset'] + $no + 1;

My two cents..

Namespacing

I notice that this project was last updated 9 months ago and has several outstanding pull requests, so I'm reluctant to make this change if you're no longer maintaining this project.

To make php-diff work with Laravel, it need to be in a namespace. If I make this change, would you merge it, or should I just fork and maintain my own copy?

composer package not working

$ ./composer.phar update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

Problem 1
    - The requested package chrisboulton/php-diff could not be found in any version, there may be a typo in the package name.

https://packagist.org/packages/chrisboulton/php-diff

s

Updates ?

Does this project receive any updates ?

First of all, I discovered a small bug. After cloning, i viewed /php-diff/example/example.php
in the browser and under the Old column of Inline Diff, line number 4 shows up twice. I don't think that's right.

The second line 4 should show under the New column.

Secondly, there are some TODOs in the README, do you plan to work on them any soon ?
After hunting around for a while, this project seems to fit best, but that small bug makes it pretty much unusable for my use case.

The TODO has -

  • Ability to ignore blank line changes
  • Performance optimizations

The first one would be nice to have, while the second one is always cool!

Let me know!

Regards

Error when not checking the count argument is an array

PHP Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in /Diff/SequenceMatcher.php:353

$aLength = count($this->a);
$bLength = count($this->b);

Please fix by replacing with this :

$aLength = is_array($this->a) ? count($this->a) : 0;
$bLength = is_array($this->b) ? count($this->b) : 0;

Inline Style: $toLine in wrong <th>

I have changed the $toLine placement from the left to the right in inline.php on line number 131.

From:

foreach($change['changed']['lines'] as $no => $line) {
 $toLine = $change['changed']['offset'] + $no + 1;
 $html .= '<tr>';
 $html .= '<th>'.$toLine.'</th>';
 $html .= '<th>&nbsp;</th>';
 $html .= '<td class="Right"><span>'.$line.'</span></td>';
 $html .= '</tr>';
}

To:

foreach($change['changed']['lines'] as $no => $line) {
 $toLine = $change['changed']['offset'] + $no + 1;
 $html .= '<tr>';
 $html .= '<th>&nbsp;</th>';
 $html .= '<th>'.$toLine.'</th>';
 $html .= '<td class="Right"><span>'.$line.'</span></td>';
 $html .= '</tr>';
}

make diff on new file

I use this script recursively on several files, all good except when I create a new file, this one does not appear because there is no file to create a diff. How do I add this option?

Chinese Charset "特色" Can Cause Crash

Hello,I'm from China.
When I use this php-diff,I was surprised! It's awsome!
but when I diff tow file like follow:
a.txt
构建具有**特色的医学人才培养体系
b.txt
构建具有**的医学人才培养体系
The php-diff crashed!

composer install does not work

When I try to invoke composer install on the newly cloned project, I get the following error-message:

[Composer\Json\JsonValidationException]
"./composer.json" does not match the expected JSON schema:
- authors[0].email : Invalid email

Line numbers on unified diff

Hi Chris

Thanks for the great work!!

just wondering if its possible to get the line numbers printed on the unified diffs (github style) ?

Cheers

Justin

Support for diffing unicode characters

Hello! I found that this code cannot be used to diff between unicode characters. When trying to do that, the highlighted lines became blank. This issue can be fixed easily - Just use multibyte string function[1] instead of string function. Also, replace string indexing to mb_substr($str, $i, 1).

Cheers

Links
[1] - http://php.net/manual/en/ref.mbstring.php

tupleSort() & realquickRatio() bug? report

file: SequenceMatcher.php

line num: 634
$bLength = count ($b);
=>
$bLength = count ($this->b);

line num: 732
if(count($a) == $count($b)) {
=>
if(count($a) == count($b)) {

Want to see the whole file

When looking at the Side by Side diff, it shows me something like:


1
2
3
4
5
6

54
55
56


You can see it "compacted" something with those three dots (...). How can I fix it so I would see the whole file?

The library itself works great! I tested another PHP diff library and it didn't respect the TABs in the output.

Highlight mark to much sometimes - (bug/feature request)

When i make a diff between:

OLD

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

NEW

Lorem aIpsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Loremb Ipsum.

Its highlight whole:

aIpsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Loremb

not only 'a' and 'b' letter.

wrap test

In the compare side by side is possible to wrap text?
I'm compare for example two switches configurations that have for example encrypt password that are two long and to compare the version the "new version" only possible scrolling the browser to the left.

Thanks.

The __construct function produces Deprecated in php8 error

The __construct function in SequenceMatcher produces Deprecated: Optional parameter $junkCallback declared before required parameter $options is implicitly treated as a required parameter [i.e. $junkCallback has a default but $options does not]

public function __construct($a, $b, $junkCallback=null, $options)

Quick fix might be :

public function __construct($a, $b, $junkCallback=null, $options=null)

ATTENTION! Don't use this package and any forks, use sebastian/diff instead

This package (chrisboulton/php-diff) is abandoned and not supported for several years. There's 167 other packages that forked from this root repo, but they are ugly. Most of them doesn't contain any changes. Many other contain questionable changes. A small number of forks contains 1-2 fixes or addition of some functionality necessary to authors. But all these forks are very low quality. Most of forks (as of original repo) doesn't use namespaces which makes difficulties if you want to use Composer's autoloader. There is a few repos that adds namespaces, but they seems to be abandoned too. They mostly are missing "Issues" section, so nobody can report a bug. Code quality is not good enough (at least for me). No unit-tests, no docs, no UTF-8 support. And all forks are crashes with count(): Parameter must be an array or an object that implements Countable when you making a diff for two arrays where one of them is empty. The error is in lib/Diff/SequenceMatcher.php in setSeq1() and setSeq2() (need replace if($a == $this->a) { to if($a === $this->a) {). This is very simple bug, but nobody found it and fixed.

I've tried these packages:

  1. chrisboulton/php-diff -- no namespaces, no multi-byte encodings
  2. phpspec/php-diff -- fixed some bugs, possible added multi-byte encodings, but still not namespaces, no Issues section
  3. adaptivemedia/php-text-difference -- added namespaces, but no Issues section, no Composer package, dev-stability
  4. JBlond/php-diff -- looks like supported, has Issues section, but no namespaces...

Then I found a better alternative of all this misunderstanding -- it's sebastian/diff (https://github.com/sebastianbergmann/diff). It works little different, but it has much better code quality, actively maintaining, supported and the author is an authority in PHP world (he maintain PHPUnit). Actually previously it was a part of PHPUnit but then was factored out. So I recommend to use his package instead and forget about chrisboulton/php-diff and all its forks.

Support diffing recursive arrays / objects

I would very much like the ability to diff recursive arrays and display them in a nice HTML side-by-side view. My particular use is in comparing versions of MongoDB records that can be several levels deep.

Download by composer

Could you configure this package in packagist. It is added, but i can't download it.
I think that the problem is in source link.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.