• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..22-Feb-2022-

.github/workflows/H23-Oct-2021-4634

src/H03-May-2022-1,547701

.editorconfigH A D23-Oct-2021232 1511

.php-cs-fixer.dist.phpH A D03-May-20223 KiB7370

LICENSEH A D23-Oct-20211.2 KiB2419

README.mdH A D23-Oct-20212.5 KiB8465

composer.jsonH A D23-Oct-20211 KiB4140

phpstan.neon.distH A D23-Oct-2021423 1310

README.md

1[![Tests](https://github.com/lolli42/FineDiff/actions/workflows/tests.yml/badge.svg)](https://github.com/lolli42/FineDiff/actions/workflows/tests.yml)
2
3FineDiff
4========
5
6FineDiff is a rather simple library to create HTML diff view of two string:
7
8```php
9echo (new Diff())->render('hello world', 'hello2 worlds');
10```
11```
12hello<ins>2</ins> world<ins>s</ins>
13```
14
15Installation
16------------
17
18```
19composer req lolli42/finediff
20```
21
22Tags
23----
24
25* **1.x** Dropped PHP <7.2, has PHP >=7.2 support, added multibyte support, forces strict types, E_ALL error free
26* **<1.x** is identical to cogpowered/finediff from ([https://github.com/cogpowered/FineDiff](https://github.com/cogpowered/FineDiff))
27
28Usage
29-----
30
31Render the difference between two strings as HTML on a character basis:
32```php
33echo (new Diff())->render('string one', 'string two');
34```
35```
36string <ins>tw</ins>o<del>ne</del>
37```
38
39Render the difference between two strings as HTML on a word basis:
40```php
41echo (new Diff(new Word()))->render('string one', 'string two');
42```
43```
44string <del>one</del><ins>two</ins>
45```
46
47Special characters and entities are quoted by HTML renderer and multibyte strings are handled:
48```php
49echo (new Diff())->render('foo<bär>baz', 'foo<qüx>baz');
50```
51```
52foo&lt;<del>b&auml;r</del><ins>q&uuml;x</ins>&gt;baz
53```
54
55Algorithm
56---------
57
58To create a diff-view between two string, an intermediate "Opcode" representation
59is created that specifies the differences form string one to string two. The renderer
60then takes this opcode and creates HTML from it. Note the opcode string is considered
61internal and may change in a backwards breaking way with younger library releases.
62
63```php
64$diff = new Diff();
65echo $diff->getOpcodes('hello world', 'hello2 worlds');
66// c5i:2c6i:s
67// Means: copy 5 chars "hello", then insert "2", then copy 6 chars " world", then insert "s"
68echo $diff->process('hello wordl', 'c5i:2c6i:s');
69// hello<ins>2</ins> world<ins>s</ins>
70```
71
72History
73-------
74
75* Originally written by Raymond Hill ([https://github.com/gorhill/PHP-FineDiff](https://github.com/gorhill/PHP-FineDiff))
76* Tweaked to bring it up to date with the modern world. That means documented, nicely formatted, tested code
77  that can be easily extended by Rob Crowe ([https://github.com/cogpowered/FineDiff](https://github.com/cogpowered/FineDiff))
78* Added PHP 8 compatibility and multibyte string support by Christian Kuhn ([https://github.com/lolli42/FineDiff](https://github.com/lolli42/FineDiff))
79
80License
81-------
82
83MIT License. See LICENSE file.
84