PHPackages                             logue/php-merge - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. logue/php-merge

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

logue/php-merge
===============

A PHP merge utility using the Diff php library or the command line git.

2.0.1(7y ago)012[1 PRs](https://github.com/logue/php-merge/pulls)MITPHPPHP ^7.1CI failing

Since Mar 18Pushed 3y ago1 watchersCompare

[ Source](https://github.com/logue/php-merge)[ Packagist](https://packagist.org/packages/logue/php-merge)[ Docs](https://github.com/bircher/php-merge)[ RSS](/packages/logue-php-merge/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (10)Versions (8)Used By (0)

php-merge
=========

[](#php-merge)

[![Build Status](https://camo.githubusercontent.com/a4cd5927da014c49270992b5d9a886617ab16a7833f083898ef52550eda7f6b6/68747470733a2f2f7472617669732d63692e6f72672f626972636865722f7068702d6d657267652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/bircher/php-merge)[![Code Coverage](https://camo.githubusercontent.com/b411a2f7a57fad61c1b1862d6e716da33ba3589e3a567d50b805e3e89d7c6d07/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f626972636865722f7068702d6d657267652f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/bircher/php-merge/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/a6f5159ae8922685feac75ec0bdf9c55d6463a13761ab62f367c8e1b67f1120b/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f626972636865722f7068702d6d657267652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/bircher/php-merge/?branch=master)[![SensioLabsInsight](https://camo.githubusercontent.com/1a8e2e0e2426ed464526888ec6e360a3c505274f57f2d3a0ae5d987651cdcbaa/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f65393339393136342d326237642d343335312d393761652d6136303034343264316534372f6d696e692e706e67)](https://insight.sensiolabs.com/projects/e9399164-2b7d-4351-97ae-a600442d1e47)[![GitHub license](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](https://raw.githubusercontent.com/bircher/php-merge/master/LICENSE.txt)

Introduction
------------

[](#introduction)

When working with revisions of text one sometimes faces the problem that there are several revisions based off the same original text. Rather than choosing one and discarding the other we want to merge the two revisions.

Git does that already wonderfully. In a php application we want a simple tool that does the same. There is the [xdiff PECL extension](http://php.net/manual/en/book.xdiff.php)which has the [xdiff\_string\_merge3](http://php.net/manual/en/function.xdiff-string-merge3.php)function. But `xdiff_string_merge3` does not behave the same way as git and xdiff may not be available on your system.

PhpMerge is a small library that solves this problem. There are two classes: `\PhpMerge\PhpMerge` and `\PhpMerge\GitMerge` that implement the `\PhpMerge\PhpMergeInterface` which has just a `merge` method.

`PhpMerge` uses `SebastianBergmann\Diff\Differ` to get the differences between the different versions and calculates the merged text from it. `GitMerge` uses `GitWrapper\GitWrapper`, writes the text to a temporary file and uses the command line git to merge the text.

Usage
-----

[](#usage)

Simple example:

```
use PhpMerge\PhpMerge;

// Create a merger instance.
$merger = new PhpMerge();

// Get the texts to merge.
$original =
