Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Php Diff Laravel Package

jfcherng/php-diff

jfcherng/php-diff is a comprehensive PHP library for generating diffs between two strings. It provides text renderers (Context, JSON, Unified) and HTML renderers (Combined, Inline, JSON, Side by Side). Install via Composer; requires PHP 8.3+ and ext-iconv. HTML output needs CSS for proper visualizat...

View on GitHub
Deep Wiki
Context7

A comprehensive library for generating differences between two strings in multiple formats (unified, side by side HTML etc).

Frequently asked questions about Php Diff
How do I install jfcherng/php-diff in a Laravel application?
Install it with composer require jfcherng/php-diff. The package is framework-agnostic, so there is no service provider, facade, or config file to publish and nothing is auto-discovered. Your environment must run PHP 8.3 or newer and have ext-iconv enabled, so verify the extension in your container image and CI matrix rather than assuming it. Most teams add a thin wrapper service provider and config file on top so the Jfcherng\Diff namespaces only appear in one place.
Which Laravel versions and PHP versions does jfcherng/php-diff support?
The library requires PHP 8.3 or higher plus ext-iconv, and it is not tied to any Laravel release. It works with any Laravel version whose PHP floor is at least 8.3, including Laravel 11 and 12 on current PHP builds. The PHP requirement is the real gate: a Laravel 11 app still pinned to PHP 8.2 cannot adopt this package without upgrading PHP first.
How do I render a side-by-side HTML diff in Laravel?
Use DiffHelper::calculate($old, $new, 'SideBySide') for the quick path, or build a Differ and a renderer through RendererFactory when you need custom options. The HTML renderers output markup only, so you must ship CSS for correct visualization. DiffHelper::getStyleSheet() returns the bundled example/diff-table.css if you want a starting point, or you can write your own styles from scratch.
What diff output formats are available in jfcherng/php-diff?
Text renderers are Context, Unified, and Json in plain text. HTML renderers are Combined, Inline, Json as HTML, and Side by Side. The JSON output is a good fit when you want to persist or cache a diff instead of recomputing it on every read. Pick the renderer based on whether the consumer is a human viewer or a machine pipeline.
Why is my diff output empty or truncated for large strings?
The Myers algorithm is O(ND), and DifferOptions ships with a lengthLimit of 2000 as a built-in circuit breaker. When input exceeds that limit the library degrades silently, returning truncated or empty output rather than throwing an exception. Raise the limit only when you can afford the CPU cost, especially if you enable character- or word-level detailLevel settings. Large or user-supplied content should never be diffed synchronously inside a web request; move it to a queued job and enforce a hard input cap at your application boundary.
How do I ignore whitespace, case, or line endings when generating a diff?
These are controlled through DifferOptions via ignoreWhitespace, ignoreCase, and ignoreLineEnding. They are correctness switches, not cosmetic tweaks, so choose defaults per content domain. For code and configuration diffs you generally want whitespace significant, while prose or normalized text comparisons may safely ignore it. Set these in your wrapper config so callers cannot accidentally pick a misleading comparison mode.
Is jfcherng/php-diff safe to run against untrusted user input (XSS)?
The bundled HTML renderers escape entities in their samples, which is a good sign, but you should not infer full XSS safety from the README alone. Write an explicit adversarial test that feeds hostile markup, script tags, and encoding edge cases through every renderer you expose. If you display diffs of user content, escape again at your Blade layer or sanitize the final HTML with an allowlist. Also keep the diff CSS under your control rather than accepting styles from the request.
Does jfcherng/php-diff work with Laravel Octane and Swoole?
Yes. The library is stateless with no global mutable state or I/O, so there is nothing to reset between requests. Renderers can safely be bound as container singletons or instantiated per call. The only operational concern is CPU time, so keep very large diff jobs out of the request cycle and dispatch them to queues.
How do I migrate from php-diff v6 or chrisboulton/php-diff to v7?
Version 7 replaced the 6.x array options with typed DifferOptions and RendererOptions objects, which is a genuine breaking change. The migration is mechanical but involves touching every call site that passed option arrays. Greenfield projects should pin ^7.0 and wrap the library in a small internal service so the next major becomes a one-file upgrade rather than a codebase-wide sweep. Projects coming from the ancestor chrisboulton/php-diff should expect namespace and API differences and rewrite integration code rather than copying it.
Is jfcherng/php-diff actively maintained, and what are the alternatives?
It is effectively a single-maintainer project with a few hundred GitHub stars and thin ecosystem validation, so there is little external pressure against breaking changes. There is no visible LTS or security policy, though the BSD-3-Clause license means you can fork and maintain it internally if upstream stalls. If you want a lighter dependency, sebastian/diff covers unified and side-by-side needs with broader adoption, while chrisboulton/php-diff is the older ancestor. Whichever you pick, keep it behind your own adapter layer so swapping is cheap.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator
equipc/laravel-email-database-log
adedsec/nova-translated-labels