sokil / php-diff
0.4
2019-07-04 19:49 UTC
Requires
- php: ^5.6 || ^7.0
- sebastian/diff: >=1.4 <4.0
Requires (Dev)
- phpunit/phpunit: >=5.5
- satooshi/php-coveralls: >=0.7.1 <2.0
This package is auto-updated.
Last update: 2024-12-05 07:33:33 UTC
README
Highlight diffs provided by Sebastian Bergmann diff
Installation
composer.phar require sokil/php-diff
Useage
<?php 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']) ));
Format of diff output
Format of diff tags may be configured. By default renders only two tags: <ins>
and <del>
. To
highlight output, use predefined format:
<?php $renderer = new Renderer([ 'format' => Renderer::FORMAT_COLOUR ]);
This will produce following HTML:
line1 <del style="background: #ffe7e7;">line2</del> <ins style="background: #ddfade;">line2changed</ins> line3
To fully customize style, use next syntax (this format has alias Renderer::FORMAT_COLOUR
):
<?php $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 ]);
Default format Renderer::FORMAT_DEFAULT
has following notation:
<?php $renderer = new Renderer([ 'insert' => [ 'tag' => 'ins', ], 'delete' => [ 'tag' => 'del', ] ]); // this is same to $renderer = new Renderer([ 'format' => Renderer::FORMAT_DEFAULT ]);