Naming language identifiers for php-diff
v7ISO 639-2/B naming convention. This ensures compatibility and standardized identification of languages within the library.repository·v7·Indexed 19 days ago
https://github.com/jfcherng/php-diffA comprehensive PHP library for generating differences between two strings or files. It supports multiple output formats, including plain text (Unified, Context, JSON) and rich HTML (Side-by-Side, Inline, Combined). The library provides granular control over diff detail levels (line, word, char) and includes dedicated configuration objects DifferOptions and RendererOptions for managing comparison behavior and visual output.
ISO 639-2/B naming convention. This ensures compatibility and standardized identification of languages within the library.final keyword. This means you can no longer extend these classes via inheritance. If your implementation relies on extending library classes, you should consider using composition instead to ensure compatibility with future updates.When using HTML-based renderers, you can control the granularity of the diff using the detailLevel option. Supported levels include:
line (Default): Shows differences at the line level.word: Shows differences at the word level.char: Shows differences at the character level.none: Shows no detailed diff within lines.Install the jfcherng/php-diff package using Composer to generate diffs between two strings in various formats (Text and HTML).
composer require jfcherng/php-diffWhen upgrading to v4, the Jfcherng\Diff\Utility\SequenceMatcher class has been moved to a standalone package. To continue using it, you must install the new package and update your namespace references.
Migration Steps:
jfcherng/php-sequence-matcher.Jfcherng\Diff\SequenceMatcher (instead of Jfcherng\Diff\Utility\SequenceMatcher).# Install the new package via composer
composer require jfcherng/php-sequence-matcher
# Update your use statements
# FROM:
use Jfcherng\Diff\Utility\SequenceMatcher;
# TO:
use Jfcherng\Diff\SequenceMatcher;Diff class has been renamed to Differ. To maintain compatibility, you must update your code to use the new class name.When upgrading to version 3, the location and availability of certain configuration options have changed:
$diffOptions: charLevelDiff and separateBlock are no longer valid keys in the $diffOptions array.$templateOptions:detailLevel: This replaces the functionality of the old charLevelDiff. Refer to the documentation for specific valid values.separateBlock: This is the new location for the separateBlock option, which was previously in $diffOptions.In version 4, all factory classes previously located under the Jfcherng\Diff\Utility\ namespace have been moved to the Jfcherng\Diff\Factory\ namespace.
Example Mapping:
Jfcherng\Diff\Utility\RendererFactory $\rightarrow$ Jfcherng\Diff\Factory\RendererFactory// Example of namespace change
// FROM:
use Jfcherng\Diff\Utility\RendererFactory;
// TO:
use Jfcherng\Diff\Factory\RendererFactory;In version 5, method names involving a, b, from, to, or base, changed were renamed to old, new to improve consistency. If you are upgrading from a version prior to v5, update your calls to the following methods:
Diff::setAB() $\rightarrow$ Diff::setOldNew()Diff::setA() $\rightarrow$ Diff::setOld()Diff::setB() $\rightarrow$ Diff::setNew()Diff::getA() $\rightarrow$ Diff::getOld()Diff::getB() $\rightarrow$ Diff::getNew()// Old v4 style
$diff->setAB($oldText, $newText);
$old = $diff->getA();
// New v5 style
$diff->setOldNew($oldText, $newText);
$old = $diff->getOld();In version 6 and later, the responsibility for rendering has shifted. The Differ class no longer contains a render() method. Instead, you must use a Renderer instance to perform the rendering by passing the Differ object into the renderer's render() method.
use Jfcherng//
use Jfcherng//
$differ = new Differ(explode("\n", $old), explode("\n", $new), $diffOptions);
$renderer = RendererFactory::make($rendererName, $rendererOptions);
$result = $renderer->render($differ); // <-- this line has been changedTo view the web-based demonstration of the library, you must first install the project dependencies from the root directory using composer install. Once dependencies are installed, you can start the built-in PHP development server and access the demo via your browser.
composer run-script server.http://localhost:12388/demo_web.php.# From the project root
composer install
composer run-script server