vi-kon / laravel-diff
Diff tool for Laravel 5
Installs: 22 518
Dependents: 1
Suggesters: 0
Security: 0
Stars: 30
Watchers: 2
Forks: 9
Open Issues: 2
Requires
- php: >=5.5.9
This package is not auto-updated.
Last update: 2021-03-05 22:44:56 UTC
README
This package is for comparison strings and show changes.
Table of content
Features
- compare strings
- compare files
- group string differences into hunk groups
Installation
Via composer
:
composer require vi-kon/laravel-diff
Usage
Simple usage:
// Compare string line by line $diff = Diff::compare("hello\na", "hello\nasd\na"); // Outputs span, ins, del HTML tags, depend if entry // is unmodified, inserted or deleted echo $diff->toHTML();
Compare two file:
// Compare files line by line $diff = Diff::compareFiles("a.txt", "b.txt"); echo $diff->toHTML();
You can customize output by getting raw data:
$options = [ // Compare by line or by characters 'compareCharacters' => false, // Offset size in hunk groups 'offset' => 2, ]; $diff = Diff::compare("hello\na", "hello\nasd\na", $options); $groups = $diff->getGroups(); foreach($groups as $i => $group) { // Output: Hunk 1 : Lines 2 - 6 echo 'Hunk ' . $i . ' : Lines ' . $group->getFirstPosition() . ' - ' . $group->getLastPosition(); // Output changed lines (entries) foreach($group->getEntries() as $entry) { // Output old position of line echo $entry instanceof \ViKon\Diff\Entry\InsertedEntry ? '-' : $entry->getOldPosition() + 1; echo ' | '; // Output new position of line echo $entry instanceof \ViKon\Diff\Entry\DeletedEntry ? '-' : $entry->getNewPosition() + 1; echo ' - '; // Output line (entry) echo $entry; } }
License
This package is licensed under the MIT License