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

Product Decisions This Supports

  • Version history and audit-trail UI. Any Laravel product that stores revisions of content—CMS pages, wiki/docs, policy text, product copy, e-signature snapshots, CRM record history—needs a "what changed" view. This package supplies the engine and the presentation layer, so the decision shifts from "do we build a diff engine?" to "which surfaces get a diff view first?"
  • Editorial and approval workflows. Reviewers approving a submitted edit want the delta, not the full document. Inline and side-by-side HTML renderers map directly to an approval queue; word/char-level detail levels let you tune how forensic the review needs to be per content type.
  • Compliance and legal-change notifications. Terms of Service, privacy policies, and regulated disclosures require showing subscribers exactly what changed between versions. The Unified and Context text renderers are the right primitive for email digests; JSON renderers let you persist a machine-readable change record alongside the notification.
  • Config and environment drift detection. Comparing .env snapshots, feature-flag payloads, translation files, or tenant settings is the same string-diff problem. ignoreWhitespace, ignoreLineEnding, and ignoreCase exist precisely for these noisy inputs.
  • Import and reconciliation previews. Before committing a bulk import or sync, show a before/after diff of affected records. This converts a "trust us" operation into a reviewable one.
  • Roadmap triage: build vs. buy. A correct diff algorithm (LCS/Myers with unicode and whitespace handling) plus four HTML layouts plus CSS is weeks of engineering and a permanent maintenance tail. Adopting this package collapses that to a dependency and frees the roadmap slot for the product surface around the diff.
  • Deferred rendering architecture. The Json renderers let you compute and store a diff once (cheaply, at write time), then re-render it in any format later without recomputation. That is a genuine architectural decision this package enables, not just an implementation detail.

When to Consider This Package

Consider adoption when:

  • The product runs PHP 8.3+ and needs server-side diff generation inside Laravel—no separate service, no JS round-trip.
  • You need multiple output formats from one diff: HTML for the UI, unified/context text for email and CLI, JSON for storage.
  • Reviewability matters and you want configurable granularity (detailLevel of none/line/word/char) and configurable noise suppression (case, whitespace, line endings, tab width).
  • You want precomputed, persisted diffs for audit history, rendered on demand via renderArray().
  • You want an escape hatch from the one-liner API: Differ + RendererFactory are composable, and renderers are pluggable.
  • You need the work done in a request/queue, not in the browser.

Look elsewhere when:

  • You need real-time collaborative editing (operational transforms or CRDTs). This is a snapshot differ, not a concurrency model.
  • You need three-way merge or conflict resolution. Not in scope here.
  • Inputs are large and numerous: lengthLimit (default 2000, primarily for char-level) signals the performance envelope. Mass-diffing thousands of large documents per request is not this tool's job—batch it or reconsider.
  • You need syntax-highlighted source-code diffs. This gives you diff structure and HTML spans; syntax coloring is a separate concern you'd layer on.
  • Your UI team would rather diff client-side on already-loaded text (jsdiff-style) and you don't need persisted, server-authoritative change records.
  • Your platform is still on PHP < 8.3, or you cannot add ext-iconv.
  • You need a vendor with a support contract or SLA. This is a single-maintainer open-source library; plan accordingly.

Adoption caveats to price in: BSD-3-Clause is permissive and commercially safe, but the project is small (≈484 stars, no downstream dependents surfaced in this scan) and bus-factor exposure is real. HTML output requires you to supply CSS (DiffHelper::getStyleSheet() gives a default), and rendered user content must be escaped and sanitized—treat diff output as untrusted HTML in the same way you'd treat any rich-text path.

How to Pitch It (Stakeholders)

For executives (one paragraph): We need "show what changed" across content history, approvals, and compliance notifications—capabilities already on the roadmap. The underlying diff algorithm plus four presentation formats is a deceptively expensive thing to build and an ongoing maintenance liability. jfcherng/php-diff is a mature, permissively licensed (BSD-3), actively released PHP library that delivers it as a dependency. Adopting it removes a multi-week build from the roadmap, carries no license cost or commercial restriction, and lets us ship the user-facing features—audit views, review queues, change digests—rather than the plumbing beneath them. The main risk is maintainer concentration, which we mitigate by keeping our usage behind a thin internal adapter so the library is replaceable.

For engineering (the short version): Composer-installable, PSR-12, PHP 8.3+, ext-iconv only. Clean two-layer design: Differ produces the change model, RendererFactory renders it. Three integration paths, in increasing control: DiffHelper::calculate() / calculateFiles() for one-liners; new Differ(...) plus a renderer for custom flows; and Json output persisted to the database with renderArray() at display time—so you compute once at write and re-render in HTML, unified, or context later without recomputing. Options cover context lines, case/whitespace/line-ending insensitivity, granularity (none/line/word/char), line numbers, block separators, tab width, and a lengthLimit guard for pathological inputs. Renderers are pluggable if we ever need something bespoke. Our integration work is a service class, a Blade partial, the stylesheet, and output escaping—not an algorithm.

For design and content stakeholders: The renderers are the four layouts you'd expect—side-by-side, inline, combined (no line numbers, suited to prose and articles), and unified/context for text contexts like email. Granularity is a per-surface choice: line-level for code and config, word- or character-level for prose where a single changed sentence should highlight only the changed words.

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.
mehedimi/laravel-amp-mail
happones/laravel-vue-i18n-generator
jwerd/inertia-table
siberfx/flysystem-wasabi
hollyit/token-replace
ippanelcom/laravel-sdk
adachsoft/changelog-linter
adachsoft/collection
payerurl/telegrambot-crypto-payment-instant-payout
dskripchenko/laravel-hybrid-search
riorizkyrainey/lara-ced
mehedimi/static-vel
zharp/zharp
nonsapiens/bigquery-model-sync
lgu-bayambang-ict-office/lgu-laravel-development-standards
andydefer/laravel-support
se7enxweb/flysystem
lampwick/laravel
jeslage/statamic-emojis
micahdshackelford/rmap-laravel