PHP code example of sokil / php-diff

1. Go to this page and download the library: Download sokil/php-diff library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sokil / php-diff example snippets




use Sokil\Diff\Change;
use Sokil\Diff\Renderer;

$diffRenderer = new Renderer();
$actualDiff = $diffRenderer->render(new Change(
    implode(PHP_EOL, ['line1', 'line2', 'line3']),
    implode(PHP_EOL, ['line1', 'line2changed', 'line3'])
));



$renderer = new Renderer([
    'format' => Renderer::FORMAT_COLOUR
]);


$renderer = new Renderer([
    'format' => [
        'insert' => [
            'tag' => 'ins',
            'attributes' => 'style="background: #ddfade;"',
        ],
        'delete' => [
            'tag' => 'del',
            'attributes' => 'style="background: #ffe7e7;"',
        ]
    ]
]);

// this is same to
$renderer = new Renderer([
    'format' => Renderer::FORMAT_COLOUR
]);


$renderer = new Renderer([
    'insert' => [
        'tag' => 'ins',
    ],
    'delete' => [
        'tag' => 'del',
    ]
]);

// this is same to
$renderer = new Renderer([
    'format' => Renderer::FORMAT_DEFAULT
]);

composer.phar