A comprehensive library for generating differences between two strings in multiple formats (unified, side by side HTML etc). Based on the difflib implementation in Python

Overview

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.
Comments
  • composer package not working

    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

    opened by ghost 3
  • PHP7 Compatibility - remove preg_match with /e modifier

    PHP7 Compatibility - remove preg_match with /e modifier

    This PR fixes PHP7 compatibility - I doubt anyone will merge it back to the upstream repo as that looks almost abandoned - however here it is for those of you like me that this broke for when they started using PHP7

    opened by PhilETaylor 2
  • Make `Diff_Renderer_Html_Array::formatLines` method protected

    Make `Diff_Renderer_Html_Array::formatLines` method protected

    would be nice to have Diff_Renderer_Html_Array::formatLines method protected rather than private so classes extending it can use the method (say you create Diff_Renderer_SideBySide_Html class)

    opened by petrkotek 2
  • Added note about jQuery-Merge-for-php-diff

    Added note about jQuery-Merge-for-php-diff

    Hello Chris,

    i've just written a jQuery plugin. It can be used to merge the files compared by php-diff. I thought you and users of php-diff might find that usefull. Due to the lack of an email address or private message system i builded this pull request containing a litte hint in your readme :)

    Thanks for your work!

    opened by Xiphe 2
  • Fix fatal error under php 8

    Fix fatal error under php 8

    String offset access with curly braces is no longer allowed in php 8.

         Fatal error: Array and string offset access syntax with curly braces is    
         no longer supported in                                                     
         /home/circleci/project/vendor/chrisboulton/php-diff/lib/Diff/Renderer/Htm  
         l/Array.php on line 153   
    

    ping @chrisboulton

    opened by joec4i 1
  • PHP7 compatibility: Avoid using 'e' modifier in preg_replace

    PHP7 compatibility: Avoid using 'e' modifier in preg_replace

    There is already plenty of PRs trying to fix this: https://github.com/chrisboulton/php-diff/pull/32 https://github.com/chrisboulton/php-diff/pull/36, https://github.com/chrisboulton/php-diff/pull/39, and https://github.com/chrisboulton/php-diff/pull/41.

    I liked the best solution from https://github.com/chrisboulton/php-diff/pull/41, however I decided to polish it a bit and add test coverage to demostrate that it still works the same.

    opened by petrkotek 1
  • Fixing some code declarations

    Fixing some code declarations

    So I'm using php-diff in a project of mine, and I ran a php-lint like software called xref, https://github.com/gariev/xref , and it pointed me to two different possible bugs in the php-diff code. I've tested this change as best as I can, but I'm not 100% sure I was ever even hitting this code.

    I'm submitting this too you in the hopes of you either telling me that no these aren't bugs, or yes they are.

    Either way, I just want to say thanks, and I appreciate you putting this library together in the first place.

    Cheers,

    opened by mhwest13 1
  • Fix an issue with insertions being skipped.

    Fix an issue with insertions being skipped.

    Looks like you accidentally skipped insertions on each loop, when they should only be skipped on the first loop. The second loop should be skipping deletions instead.

    opened by dgarrett 1
  • Fix multiple space rendering

    Fix multiple space rendering

    The code tries to replace multiple spaces with "nbsp; " and "nbsp;" depending on whether it is odd or even. The original preg_replace is only capturing the trailing spaces, but replacing all of them, which means the first space always gets silently dropped.

    opened by adipose 4
  • ATTENTION! Don't use this package and any forks, use sebastian/diff instead

    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.

    opened by gugglegum 6
  • utf-8 strings support

    utf-8 strings support

    There are two commits: first - remove uneeded /span tag second - addede utf-8 string correct handling. I add as function. But if you want then I can restyle or refactor this commit. Strings for test looks like АБВ and ЭЮЯ

    opened by SpeakingFish 1
  • Add detail start/end information for replace strings

    Add detail start/end information for replace strings

    The replace strings only hold the full set string, with this change the string location for the changes is stored on the array and can be used without the html output renderer

    opened by gullevek 0
Owner
Chris Boulton
VP, Infrastructure @ BigCommerce
Chris Boulton
YCOM Impersonate. Login as selected YCOM user 🧙‍♂️in frontend.

YCOM Impersonate Login as selected YCOM user in frontend. Features: Backend users with admin rights or YCOM[] rights, can be automatically logged in v

Friends Of REDAXO 17 Sep 12, 2022
World countries - available in multiple languages, in CSV, JSON, PHP, SQL and XML formats

Constantly updated lists of world countries and their associated alpha-2, alpha-3 and numeric country codes as defined by the ISO 3166 standard, available in CSV, JSON , PHP, SQL and XML formats, in multiple languages and with national flags included; also available are the ISO 3166-2 codes of provinces/ states associated with the countries

Stefan Gabos 1k Dec 29, 2022
OrangeHRM is a comprehensive Human Resource Management (HRM) System that captures all the essential functionalities required for any enterprise.

OrangeHRM Open Source Application OrangeHRM is a comprehensive Human Resource Management (HRM) System that captures all the essential functionalities

OrangeHRM 452 Jan 4, 2023
Comprehensive Plugin for composer to execute PHP Quality assurance Tools

NOT MAINTANED ANYMORE The development of composer-plugin-qa was dropped in favor of phpqa which is actively maintained. The project use docker and can

Webysther Nunes 25 Apr 30, 2021
implementation of a simple Brute-force attack in python

Brute-force-attack-python implementation of a simple Brute-force attack in python using requests library who involved in this project: Python side : A

ali sharifi 5 Nov 25, 2022
PHP library for generating random avatars based on avataaars

PHP Avataaar PHP library for generating random avatars based on avataaars. Installation Dependencies PHP 8.0 Composer 2.0 Install Install the library

John Ciacia 2 Feb 27, 2022
This project is very diverse and based upon many languages and libraries such as C++, Python, JavaScript, PHP and MQTT

ADMS-Real-time-project This project is very diverse and based upon many languages and libraries such as C++, Python, JavaScript, PHP and MQTT Advance_

Nitya parikh 1 Dec 1, 2021
Silverstripe-sspy - Python based SSPAK export with higher reliability and cross-platform compatibility

SSPY - Python Stand-alone SSPAK solution © Simon Firesphere Erkelens; Moss Mossman Cantwell Usage: sspy [create|load|extract] (db|assets) --file=my.

Simon Erkelens 1 Jun 29, 2021
Dobren Dragojević 6 Jun 11, 2023
Ip2region is a offline IP location library with accuracy rate of 99.9% and 0.0x millseconds searching performance. DB file is ONLY a few megabytes with all IP address stored. binding for Java,PHP,C,Python,Nodejs,Golang,C#,lua. Binary,B-tree,Memory searching algorithm

Ip2region是什么? ip2region - 准确率99.9%的离线IP地址定位库,0.0x毫秒级查询,ip2region.db数据库只有数MB,提供了java,php,c,python,nodejs,golang,c#等查询绑定和Binary,B树,内存三种查询算法。 Ip2region特性

Lion 12.6k Dec 30, 2022
The simplest way to create a dynamic sitemap for your self-coded website which you have made by using PHP/HTML/CSS/Js etc... Scripts.

Sitemap_index.xml The simplest way to create a dynamic sitemap for your self-coded website which you have made by using PHP/HTML/CSS/Js etc... Scripts

Tanish Raj 1 Oct 16, 2021
Easy management of Virtualization technologies including KVM, Xen, OpenVZ, Virtuozzo, and LXC/LXD including unified commands, monitoring, template management, and many more features.

ProVirted About Easy management of Virtualization technologies including KVM, Xen, OpenVZ, Virtuozzo, and LXC/LXD including unified commands, monitori

null 2 Aug 22, 2022
:globe_with_meridians: List of all countries with names and ISO 3166-1 codes in all languages and data formats.

symfony upgrade fixer • twig gettext extractor • wisdom • centipede • permissions handler • extraload • gravatar • locurro • country list • transliter

Saša Stamenković 5k Dec 22, 2022
Import data from and export data to a range of different file formats and media

Ddeboer Data Import library This library has been renamed to PortPHP and will be deprecated. Please use PortPHP instead. Introduction This PHP library

David de Boer 570 Dec 27, 2022
DTO Generator - PHP library for generating DTO classes

DTO Generator PHP library for generating DTO classes. Installation Use the package manager composer to install micro/dto. composer require micro/dto U

Micro PHP Framework 6 Dec 31, 2022
html-sanitizer is a library aiming at handling, cleaning and sanitizing HTML sent by external users

html-sanitizer html-sanitizer is a library aiming at handling, cleaning and sanitizing HTML sent by external users (who you cannot trust), allowing yo

Titouan Galopin 381 Dec 12, 2022
Repo pour la Nuit de l'Info 2021, équipe Passage Python

Passage Python Repo pour la Nuit de l'Info 2021, équipe Passage Python Les membres de l'équipe sont : Florian Duzes, FloDarPie Theo Cavailles, igneefl

Florian Duzes 3 Dec 3, 2021
SERP Scraping API code examples for Python, PHP and Node.js

SERP Scraping API List of contents Introduction Authentication Google Baidu Bing Yandex Parameters Targets Languages License Introduction With our SER

Smartproxy 8 Nov 7, 2022
Library for check dependency between modules inside projects

PHP Dependency analyzer PHP DA is tool for check and support dependencies inside your project clear. For example: You have project with 3 root namespa

Kir Apukhtin 12 Nov 15, 2022