Skip to content

Commit 7a97cdd

Browse files
committed
Merge branch 'master' into development
2 parents 55a4eba + 93af655 commit 7a97cdd

31 files changed

+888
-526
lines changed

README.md

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,16 @@
66

77
## Introduction
88

9-
A comprehensive library for generating differences between
10-
two hashable objects (strings or arrays). Generated differences can be
11-
rendered in all of the standard formats including:
9+
A comprehensive library for generating differences between two hashable objects (strings or arrays).
10+
Generated differences can be rendered in all of the standard formats including:
1211
* Unified
1312
* Context
1413
* Inline HTML
1514
* Side by Side HTML
1615
* Unified HTML
1716

18-
The logic behind the core of the diff engine (ie, the sequence matcher)
19-
is primarily based on the Python difflib package. The reason for doing
20-
so is primarily because of its high degree of accuracy.
21-
17+
The logic behind the core of the diff engine (ie, the sequence matcher) is primarily based on the Python difflib
18+
package. The reason for doing so is primarily because of its high degree of accuracy.
2219

2320
## Install
2421

@@ -42,40 +39,42 @@ $b = file_get_contents(dirname(__FILE__).'/b.txt');
4239

4340
// Options for generating the diff.
4441
$options = [
45-
//'ignoreWhitespace' => true,
46-
//'ignoreCase' => true,
42+
'ignoreWhitespace' => true,
43+
'ignoreCase' => true,
44+
'context' => 2,
4745
];
4846

4947
// Initialize the diff class.
50-
$diff = new \jblond\Diff($a, $b, $options);
48+
$diff = new \jblond\Diff($a, $b /*, $options */);
5149

5250
// Choose Renderer.
5351
$renderer = new \jblond\Diff\Renderer\Html\SideBySide([
54-
'title_a' => 'Custom title for OLD version',
55-
'title_b' => 'Custom title for NEW version',
52+
'title1' => 'Custom title for OLD version',
53+
'title2' => 'Custom title for NEW version',
5654
]);
5755

5856
// Show it.
5957
echo $diff->Render($renderer);
6058
```
6159

6260
### Example Output
63-
A quick usage example can be found in the example/ directory and under
64-
example.php.
65-
66-
![Example Image](readme.png "Example")
61+
A quick usage example can be found in the `example/` directory and under example.php.
6762

68-
![Example 2 Image](readme2.png "Example2")
63+
![HTML Side By Side Example](htmlSideBySide.png "HTML Side By Side Example")
64+
![HTML Inline Example](htmlInline.png "HTML Inline Example")
65+
![HTML Unified Example](htmlUnified.png "HTML Unified Example")
66+
![Text Unified Example](textUnified.png "Text Unified Example")
67+
![Text Context Example](textContext.png "Text Context Example")
6968

7069
## Requirements
7170

7271
* PHP 7.2 or greater
73-
* PHP Multibyte String
72+
* PHP Multibyte String
7473

7574
## Merge files using jQuery
7675

77-
Xiphe has build a jQuery plugin with that you can merge the compared
78-
files. Have a look at [jQuery-Merge-for-php-diff](https://github.com/Xiphe/jQuery-Merge-for-php-diff).
76+
Xiphe has build a jQuery plugin with that you can merge the compared files.
77+
Have a look at [jQuery-Merge-for-php-diff](https://github.com/Xiphe/jQuery-Merge-for-php-diff).
7978

8079
## Todo
8180

composer.json

Lines changed: 45 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,47 @@
11
{
2-
"name" : "jblond/php-diff",
3-
"type" : "library",
4-
"description" : "A comprehensive library for generating differences between two hashable objects (strings or arrays).",
5-
"license" : "BSD-3-Clause",
6-
"keywords" : [
7-
"php",
8-
"diff"
9-
],
10-
"authors" : [{
11-
"name" : "Mario",
12-
"email" : "[email protected]"
13-
}, {
14-
"name" : "Chris Boulton",
15-
"email" : "[email protected]"
16-
}
17-
],
18-
"require" : {
19-
"php" : ">=7.2",
20-
"ext-mbstring" : "*"
21-
},
22-
"require-dev" : {
23-
"phpunit/phpunit" : "8.*",
24-
"squizlabs/php_codesniffer" : "*",
25-
"phpmd/phpmd": "2.*"
26-
},
27-
"autoload" : {
28-
"psr-4" : {
29-
"jblond\\" : "lib/jblond"
30-
}
31-
},
32-
"config" : {
33-
"classmap-authoritative" : true
34-
},
35-
"scripts" : {
36-
"phpunit" : "phpunit ./tests/",
37-
"php_src" : "phpcs --standard=phpcs.xml -s -p --colors ./lib/",
38-
"php_test" : "phpcs --standard=phpcs.xml -s -p --colors ./tests/",
39-
"phpmd" : "phpmd ./ ansi cleancode, codesize, controversial, design, naming, unusedcode --exclude vendor"
40-
}
2+
"name": "jblond/php-diff",
3+
"type": "library",
4+
"description": "A comprehensive library for generating differences between two hashable objects (strings or arrays).",
5+
"license": "BSD-3-Clause",
6+
"keywords": [
7+
"php",
8+
"diff"
9+
],
10+
"authors": [
11+
{
12+
"name": "Mario",
13+
"email": "[email protected]"
14+
},
15+
{
16+
"name": "Ferry Cools",
17+
"email": "[email protected]"
18+
},
19+
{
20+
"name": "Chris Boulton",
21+
"email": "[email protected]"
22+
}
23+
],
24+
"require": {
25+
"php": ">=7.2",
26+
"ext-mbstring": "*"
27+
},
28+
"require-dev": {
29+
"phpunit/phpunit": "8.*",
30+
"squizlabs/php_codesniffer": "*",
31+
"phpmd/phpmd": "2.*"
32+
},
33+
"autoload": {
34+
"psr-4": {
35+
"jblond\\": "lib/jblond"
36+
}
37+
},
38+
"config": {
39+
"classmap-authoritative": true
40+
},
41+
"scripts": {
42+
"phpunit": "phpunit ./tests/",
43+
"php_src": "phpcs --standard=phpcs.xml -s -p --colors ./lib/",
44+
"php_test": "phpcs --standard=phpcs.xml -s -p --colors ./tests/",
45+
"phpmd": "phpmd ./ ansi cleancode,codesize,controversial,design,naming,unusedcode --exclude vendor"
46+
}
4147
}

example/a.txt

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,32 @@
11
<html>
2-
<head>
3-
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
4-
<title>Hello World!</title>
5-
</head>
6-
<body>
7-
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
2+
<head>
3+
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
4+
<title>Hello World!</title>
5+
</head>
6+
<body>
7+
<h1>This is demo content to show features of the php-diff package.</h1>
8+
<h2>This line is removed from version2.</h2>
9+
<h2>This line is the same for both versions.</h2>
10+
<h2>This line has inline differences between both versions.</h2>
11+
<h2>This line is the same for both versions.</h2>
12+
<h2>This line also has inline differences between both versions.</h2>
13+
<h2>This line is the same for both versions.</h2>
814

9-
<h2>A heading we'll be removing</h2>
10-
<pre>
11-
构建具有中国特色的医学人才培养体系
12-
</pre>
13-
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
14-
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
15-
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
16-
<pre>
17-
另外我覺得那個評價的白色櫃子有點沒有必要欸。外觀我就不說了 ,怎麼連空間都那麼狹隘。不過倒是從這個地方看出所謂的“改革” 😅😅
18-
</pre>
19-
<p>Do you know in Chinese, "金槍魚罐頭" means tuna can.</p>
20-
</body>
15+
<p>
16+
It's also compatible with multibyte characters (like Chinese and emoji) as shown below:
17+
另外我覺得那個評價的白色櫃子有點沒有必要欸。外觀我就不說了 ,怎麼連空間都那麼狹隘。不過倒是從這個地方看出所謂的“改革”
18+
Do you know what "金槍魚罐頭" means in Chinese?
19+
🍏🍎🙂
20+
</p>
21+
22+
<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
23+
<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
24+
<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
25+
<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
26+
<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
27+
<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
28+
<h2>This line also has inline differences between both versions. It's the whitespace in front.</h2>
29+
<h2>This line is the same for both versions.</h2>
30+
<h2>This line also has inline differences between both versions.</h2>
31+
</body>
2132
</html>

example/b.txt

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,32 @@
1-
21
<html>
3-
<head>
4-
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
5-
<title>Goodbye Cruel World!</title>
6-
</head>
7-
<body>
8-
<p>Just a small amount of new text...</p>
9-
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
2+
<head>
3+
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
4+
<title>Hello You!</title>
5+
</head>
6+
<body>
7+
<h1>This is demo content to show features of the php-diff package.</h1>
8+
<h2>This line is the same for both versions.</h2>
9+
<h2>This line has differences between both versions.</h2>
10+
<h2>This line is the same for both versions.</h2>
11+
<h2>This line also has InLine differences between both versions.</h2>
12+
<h2>This line is the same for both versions.</h2>
13+
<h2>This line is added to version2.</h2>
14+
15+
<p>
16+
It's also compatible with multibyte characters (like Chinese and emoji) as shown below:
17+
另外我覺得那個評鑑的白色櫃子有點沒有必要欸。外觀我就不說了 ,怎麼連空間都那麼狹隘。不過倒是從這個地方看出所謂的“改革”
18+
Do you know what "魚の缶詰" means in Chinese?
19+
🍎🍏🙂
20+
</p>
1021

11-
<pre>
12-
构建具有中国國的医学人才培养体系
13-
</pre>
14-
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
15-
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
16-
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
17-
<pre>
18-
另外我覺得那個評鑑的白色櫃子有點沒有必要欸。外觀我就不說了 ,怎麼連空間都那麼狹隘。不過倒是從這個地方看出所謂的“改革” 😅😅
19-
</pre>
20-
<p>Do you know in Japanese, "魚の缶詰" means fish can.</p>
21-
</body>
22+
<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
23+
<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
24+
<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
25+
<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
26+
<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
27+
<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
28+
<h2>This line also has inline differences between both versions. It's the whitespace in front.</h2>
29+
<h2>This line is the same for both versions.</h2>
30+
<h2>This line also has inline differences between both versions!</h2>
31+
</body>
2232
</html>

example/example.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,16 @@
1717
$b = file_get_contents(dirname(__FILE__) . '/b.txt');
1818

1919
// Options for generating the diff.
20-
$options = [
21-
//'ignoreWhitespace' => true,
22-
//'ignoreCase' => true,
23-
//'context' => 2, /* Remove // to see text collapse in action */
20+
$customOptions = [
21+
'context' => 2,
22+
'trimEqual' => false,
23+
'ignoreWhitespace' => true,
24+
'ignoreCase' => true,
2425
];
2526

26-
// Initialize the diff class.
27-
// \jblond\diff
28-
$diff = new Diff($a, $b, $options);
27+
// Choose one of the initializations.
28+
$diff = new Diff($a, $b); // Initialize the diff class with default options.
29+
//$diff = new Diff($a, $b, $customOptions); // Initialize the diff class with custom options.
2930
?><!DOCTYPE html>
3031
<html lang="en">
3132
<head>
@@ -43,11 +44,10 @@
4344
// Generate a side by side diff.
4445
// \jblond\Diff\Renderer\Html
4546
$renderer = new SideBySide([
46-
'title_a' => 'Custom title for OLD version',
47-
'title_b' => 'Custom title for NEW version',
47+
'title1' => 'Custom title for version1',
48+
'title2' => 'Custom title for version2',
4849
]);
4950
echo $diff->Render($renderer);
50-
5151
?>
5252

5353
<h2>HTML Inline Diff</h2>

htmlInline.png

56.4 KB
Loading

htmlSideBySide.png

45.7 KB
Loading

htmlUnified.png

50.7 KB
Loading

0 commit comments

Comments
 (0)