Skip to content

Commit cb3f3d5

Browse files
committed
Improved example code.
1 parent d92c42a commit cb3f3d5

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

README.md

+21
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,27 @@ Or clone it locally via GIT, or download any of the
2727
### Comparing strings
2828

2929
```php
30+
use Mistralys\Diff\Diff;
31+
3032
$diff = Diff::compareStrings('String 1', 'String 2');
3133
```
3234

3335
### Comparing files
3436

3537
```php
38+
use Mistralys\Diff\Diff;
39+
3640
$diff = Diff::compareFiles('/path/to/file1', '/path/to/file2');
3741
```
3842

3943
Once the diff instance has been created, choose any of the `toXXX`
4044
methods to retrieve the diff in your preferred format.
4145

4246
```php
47+
use Mistralys\Diff\Diff;
48+
49+
$diff = Diff::compareFiles('/path/to/file1', '/path/to/file2');
50+
4351
$string = $diff->toString();
4452
$html = $diff->toHTML();
4553
$table = $diff->toHTMLTable();
@@ -52,6 +60,10 @@ By default, the comparison will be made per line. It can be changed
5260
to be done on a per-character basis:
5361

5462
```php
63+
use Mistralys\Diff\Diff;
64+
65+
$diff = Diff::compareFiles('/path/to/file1', '/path/to/file2');
66+
5567
$diff->setCompareCharacters(true);
5668
```
5769

@@ -62,12 +74,19 @@ changes with the integrated CSS styles. To insert these, use the
6274
`Styler` class: it offers several ways to access the CSS.
6375

6476
```php
77+
use Mistralys\Diff\Diff;
78+
79+
$diff = Diff::compareFiles('/path/to/file1', '/path/to/file2');
6580
$styler = Diff::createStyler();
6681
```
6782

6883
From here, use any of the styler's methods according to your project's needs.
6984

7085
```php
86+
use Mistralys\Diff\Diff;
87+
88+
$styler = Diff::createStyler();
89+
7190
$css = $styler->getCSS(); // get the raw CSS styles
7291
$tag = $styler->getStyleTag(); // CSS styles with a <style> tag
7392
$path = $styler->getStylesheetPath(); // absolute path to the file
@@ -77,6 +96,8 @@ $url = $styler->getStylesheetURL('/vendor'); // URL to the file, given the vendo
7796
For example, to show a highlighted diff with inline styles:
7897
7998
```php
99+
use Mistralys\Diff\Diff;
100+
80101
$diff = Diff::compareStrings('String 1', 'String 2');
81102
82103
echo Diff::createStyler()->getStyleTag();

0 commit comments

Comments
 (0)