Skip to content

webtown-php/fine-diff-bundle

Repository files navigation

FineDiffBundle

Original fine diff library:

Installation

Add to composer

Run in command line:

$ composer require webtown-php/fine-diff-bundle

Or add with hand to composer.json:

    "require": {
        "webtown-php/fine-diff-bundle": "~1.4"
    }

Register the bundle

Add the app

<?php
    // app/AppKernel.php
    
    public function registerBundles()
	{
		$bundles = array(
			// ...
			new WebtownPHP\FineDiffBundle\WebtownPHPFineDiffBundle(),
		);
	}

Configure

Optional. You can change the default granularity.

# app/config/config.yml

webtown_php_fine_diff:
    default_granularity: character # This is the default granularity. Alternatives: 'word', 'sentence' and 'paragraph'

Usage

There are two twig function:

  • renderDiff(): compare two strings
  • renderHtmlTextDiff(): compare two strings which contain HTML tags. Remove tags with strip_tags before compare strings
{{ renderDiff(oldValue, newValue) }}
{{ renderDiff(oldValue, newValue, 'word') }}

{{ renderHtmlTextDiff(oldValue, newValue) }}
{{ renderHtmlTextDiff(oldValue, newValue, 'sentence') }}