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

..21-Sep-2021-

src/cogpowered/FineDiff/H19-May-2014-1,709670

README.mdH A D19-May-20143.1 KiB12185

composer.jsonH A D19-May-2014674 2827

phpunit.xml.distH A D19-May-20141.2 KiB3837

README.md

1FineDiff
2========
3
4Originally written by Raymond Hill ([https://github.com/gorhill/PHP-FineDiff](https://github.com/gorhill/PHP-FineDiff)) FineDiff has been tweaked to bring it up to date with the modern world. That means documented, nicely formatted, tested code that can be easily extended.
5
6[![Build Status](https://travis-ci.org/cogpowered/FineDiff.png?branch=master)](https://travis-ci.org/cogpowered/FineDiff)
7
8Installation
9------------
10
11**Composer**
12
13The preferred way of using FineDiff is through [Composer](http://getcomposer.org).
14
15Add the following to your composer.json file:
16
17```json
18{
19    "require": {
20        "cogpowered/finediff": "0.3.*"
21    }
22}
23```
24
25Upgrading
26---------
27
28**0.3.x** introduces a backwards incompatible version, so if you have stored opcodes do not upgrade!
29
30`0.3.x` fixes a double encoding issue that generates a longer opcode than is needed.
31
32Usage
33-----
34
35**Render HTML**
36
37
38Render as HTML the difference between two strings:
39
40```php
41$diff = new cogpowered\FineDiff\Diff;
42echo $diff->render('string one', 'string two');
43```
44
45This would then output:
46
47```html
48string <ins>tw</ins>o<del>ne</del>
49```
50
51You could change the granularity to `cogpowered\FineDiff\Granularity\Word` so the output is:
52
53```html
54string <del>one</del><ins>two</ins>
55```
56
57You do this by passing it into the Diff constructor:
58
59```php
60$granularity = new cogpowered\FineDiff\Granularity\Word;
61$diff        = new cogpowered\FineDiff\Diff($granularity);
62```
63
64**Grab opcode instructions**
65
66Opcode instructions are what tell FineDiff how to change one string into another.
67
68```php
69$diff = new cogpowered\FineDiff\Diff;
70echo $diff->getOpcodes('string one', 'string two');
71```
72
73This would then output:
74
75```html
76c7d3i3:two
77```
78
79Render text using the opcodes:
80```php
81$render = new cogpowered\FineDiff\Render\Text;
82echo $render->process('string one', 'c7d3i3:two');
83```
84
85Would output:
86```html
87string two
88```
89
90Same with HTML:
91```php
92$render = new cogpowered\FineDiff\Render\Html;
93echo $render->process('string one', 'c7d3i3:two');
94```
95
96License
97-------
98
99Copyright (c) 2011 Raymond Hill (http://raymondhill.net/blog/?p=441)
100Copyright (c) 2013 Rob Crowe (http://cogpowered.com)
101
102Licensed under The MIT License
103
104Permission is hereby granted, free of charge, to any person obtaining a copy
105of this software and associated documentation files (the "Software"), to deal
106in the Software without restriction, including without limitation the rights
107to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
108copies of the Software, and to permit persons to whom the Software is
109furnished to do so, subject to the following conditions:
110
111The above copyright notice and this permission notice shall be included in
112all copies or substantial portions of the Software.
113
114THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
115IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
116FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
117AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
118LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
119OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
120THE SOFTWARE.
121