Skip to content

Commit ee6e5a3

Browse files
committed
Add UTF-8-ready demo
Signed-off-by: Jack Cherng <jfcherng@gmail.com>
1 parent bf686a2 commit ee6e5a3

File tree

4 files changed

+33
-8
lines changed

4 files changed

+33
-8
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ $result = $diff->render($renderer);
9090
# Rendered Results
9191

9292

93+
## UTF-8 Ready
94+
95+
![UTF-8 Ready](https://raw.githubusercontent.com/jfcherng/php-diff/gh-pages/images/utf-8-ready.png)
96+
97+
9398
## HTML Diff In-line Detail Rendering
9499

95100
<table>

example/demo.php

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,18 @@
1212

1313
use Jfcherng\Diff\DiffHelper;
1414

15-
// include two sample files for comparison
16-
$a = \file_get_contents(__DIR__ . '/a.txt');
17-
$b = \file_get_contents(__DIR__ . '/b.txt');
18-
1915
// sample string for comparison
2016
$old = "\$old = 'This is the old string.';";
2117
$new = "\$new = 'And this is the new one.';";
2218

19+
// sample string for comparison
20+
$old_u8 = '內存不足!沒法在視頻聊天時播放視頻。';
21+
$new_u8 = '記憶體不足!沒辦法在視訊聊天時播放影片。';
22+
23+
// include two sample files for comparison
24+
$old_file = \file_get_contents(__DIR__ . '/old_file.txt');
25+
$new_file = \file_get_contents(__DIR__ . '/new_file.txt');
26+
2327
// options for Diff class
2428
$diffOptions = [
2529
// show how many neighbor lines
@@ -48,6 +52,22 @@
4852

4953
?>
5054

55+
<h1>UTF-8 Ready</h1>
56+
<?php
57+
58+
// demo the UTF-8 diff
59+
$result = DiffHelper::calculate(
60+
$old_u8,
61+
$new_u8,
62+
'Inline',
63+
$diffOptions,
64+
['detailLevel' => 'char'] + $templateOptions
65+
);
66+
67+
echo $result;
68+
69+
?>
70+
5171
<h1>None-level Diff</h1>
5272
<?php
5373

@@ -116,7 +136,7 @@
116136
<?php
117137

118138
// generate a side by side diff
119-
$result = DiffHelper::calculate($a, $b, 'SideBySide', $diffOptions, $templateOptions);
139+
$result = DiffHelper::calculate($old_file, $new_file, 'SideBySide', $diffOptions, $templateOptions);
120140

121141
echo $result;
122142

@@ -126,7 +146,7 @@
126146
<?php
127147

128148
// generate an inline diff
129-
$result = DiffHelper::calculate($a, $b, 'Inline', $diffOptions, $templateOptions);
149+
$result = DiffHelper::calculate($old_file, $new_file, 'Inline', $diffOptions, $templateOptions);
130150

131151
echo $result;
132152

@@ -136,7 +156,7 @@
136156
<pre><?php
137157

138158
// generate a unified diff
139-
$result = DiffHelper::calculate($a, $b, 'Unified', $diffOptions, $templateOptions);
159+
$result = DiffHelper::calculate($old_file, $new_file, 'Unified', $diffOptions, $templateOptions);
140160

141161
echo \htmlspecialchars($result);
142162

@@ -146,7 +166,7 @@
146166
<pre><?php
147167

148168
// generate a context diff
149-
$result = DiffHelper::calculate($a, $b, 'Context', $diffOptions, $templateOptions);
169+
$result = DiffHelper::calculate($old_file, $new_file, 'Context', $diffOptions, $templateOptions);
150170

151171
echo \htmlspecialchars($result);
152172

File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)