PHP code example of ofmadsen / php-differ
1. Go to this page and download the library: Download ofmadsen/php-differ library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ofmadsen / php-differ example snippets
$algorithm = new Madsen\Diff\Algorithm\Myers();
$differ = new Madsen\Diff\Differ($algorithm);
// $a and $b are strings
$diff = $differ->diffLines($a, $b); // Also support ::diffWords()
// $diff is Madsen\Diff\Diff that can be iterated:
foreach ($diff as $chunk) {
// $chunk is an Madsen\Diff\Chunk\AbstractChunk object; AddedChunk, RemovedChunk or UnchangedChunk
$content = $chunk->getContent();
}
$added = $diff->countAdded(); // Get the number of added chunks
$removed = $diff->countRemoved(); // Get the number of removed chunks
$unchanged = $diff->countUnchanged(); // Get the number of unchanged chunks
bash
$ composer