Weave Code
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

PHP library to generate diffs between two strings with multiple renderers: unified/context/text, JSON, and rich HTML (inline, side-by-side, combined). Includes helper CSS (or your own) and customizable differ/renderer options. Requires PHP 8.3+ and ext-iconv.

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 project?
Run `composer require jfcherng/php-diff` in your project root. Ensure your server has PHP 8.3+ and the `ext-iconv` extension enabled, as required by the package.
Which Laravel versions does this package support?
The package supports Laravel 10.x+ since it requires PHP 8.3+. It has no Laravel-specific dependencies, so it works with any Laravel version meeting the PHP requirement.
Can I use this for generating HTML diffs in a Laravel Blade template?
Yes. Use the `SideBySide`, `Combined`, or `Inline` HTML renderers and include the default CSS via `DiffHelper::getStyleSheet()`. Embed the diff in Blade with `@php` directives or create a custom Blade component.
What are the best renderers for API responses vs. admin panels?
For APIs, use `JsonText` or `JsonHtml` for machine-readable diffs. For admin panels, `SideBySide` or `Combined` HTML renderers provide the most readable visual diffs for humans.
How do I handle large file diffs (e.g., 100KB+) without timeouts?
Set a `lengthLimit` in the `DifferOptions` to cap input size. For very large files, pre-process them (e.g., chunking) or use async processing with Laravel queues to avoid blocking requests.
Is there a way to integrate this with Laravel’s service container?
Yes. Bind the `Differ` class to the container manually, like `$this->app->bind(Differ::class, fn() => new Differ([], [], new DifferOptions()));`. For cleaner syntax, create a facade or use Laravel’s `make:command` for CLI tools.
Does this package support custom CSS for HTML diffs?
Yes. You can modify the default `diff-table.css` or create your own. The package provides `DiffHelper::getStyleSheet()` for the default CSS, but you can override it entirely for custom styling.
What alternatives exist if I need more active maintenance?
Consider `sebastianbergmann/diff` for a simpler, actively maintained alternative. For advanced diff algorithms, `google/diff-match-patch` (Google’s library) offers more features but requires manual integration.
How do I store diffs in a PostgreSQL database?
Use the `JsonText` or `JsonHtml` renderers to serialize diffs into JSON. Store them in a `jsonb` column for efficient querying and retrieval. For large HTML diffs, consider binary storage (e.g., S3).
Can I use this for real-time collaborative editing (e.g., like Google Docs)?
The package supports character-level diffs, which are useful for collaborative editing. However, for real-time sync, you’ll need additional logic (e.g., operational transformation) and may want to pair it with a WebSocket library like Laravel Echo.
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.
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge