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

Generate diffs between two strings in PHP with multiple renderers: unified/context text, JSON, and rich HTML (inline, side-by-side, combined). Includes configurable differ/renderer options and helper CSS for easy HTML diff styling.

View on GitHub
Deep Wiki
Context7

jfcherng/php-diff is a comprehensive PHP library for generating diffs between two strings and rendering them in common formats for CLI output, APIs, or web UIs. It includes multiple renderer styles and provides tooling to make HTML diffs easy to embed (with optional default CSS via DiffHelper::getStyleSheet()).

Features

  • Text renderers: Context, Unified, and JSON (plain text)
  • HTML renderers: Combined, Inline, Side-by-Side, and JSON (HTML)
  • Configurable behavior via DifferOptions and RendererOptions
  • Ships with example CSS (example/diff-table.css) for clean HTML output
  • Requires PHP ≥ 8.3 and ext-iconv
Frequently asked questions about Php Diff
How do I install php-diff in a Laravel project?
Run `composer require jfcherng/php-diff` in your project root. Ensure your Laravel app uses PHP 8.3+ (required for v7.0.0). The package has no framework dependencies and integrates seamlessly via Composer autoloading.
What Laravel versions does php-diff v7 support?
This version requires Laravel 10.x+ due to the PHP 8.3+ dependency. For Laravel 9.x or older, downgrade to v6.x or upgrade your PHP/Laravel stack. The package itself has no Laravel-specific dependencies.
How do I generate a side-by-side HTML diff in Blade?
Use the `RendererFactory` to create a side-by-side renderer, then pass the diff result to Blade. Example: `$renderer = RendererFactory::createSideBySideRenderer(); $html = $renderer->render($differ->calculate($oldText, $newText));` Include `DiffHelper::getStyleSheet()` in your layout for styling.
Does php-diff automatically escape HTML output to prevent XSS?
No, the HTML renderer does not auto-escape user input. Always sanitize content before passing it to the diff library. For Blade, use `|e` or `{{ }}` to escape rendered output manually.
What are the breaking changes in v7 for custom Differ/Renderer implementations?
v7 introduces `DifferOptions` and `RendererOptions` value objects, requiring constructor updates (e.g., `new Differ(new DifferOptions())`). Check the UPGRADING guide for method signature changes in custom implementations.
How does php-diff handle memory usage for large files (e.g., 1GB+)?
The core diffing algorithm remains unchanged, so memory usage scales linearly with input size. For files >100MB, consider chunking the content or using streaming approaches. No built-in memory optimizations exist for large datasets.
Can I use php-diff with Laravel’s service container for dependency injection?
Yes, bind the `Differ` and `RendererFactory` classes to the container explicitly. Example: `app()->bind(Differ::class, fn() => new Differ(new DifferOptions()));` The new value objects integrate cleanly with Laravel’s DI system.
Are there performance benchmarks for the new DifferOptions/RendererOptions?
No official benchmarks are provided in the release notes. The new options objects add minimal overhead; performance should remain comparable to v6.x for typical use cases. Test with your workload if precision is critical.
How do I migrate from v6.x to v7.0.0 in a Laravel app?
1) Update `composer.json` to require `^7.0`. 2) Upgrade PHP to 8.3+. 3) Replace direct `Differ`/`Renderer` instantiations with the new options objects. 4) Test Blade templates and edge cases. Use the UPGRADING guide for constructor/method changes.
What alternatives exist for generating diffs in Laravel?
Consider `sebastianbergmann/diff` (simpler, no HTML), `phpoffice/phpdiff` (file-level diffs), or `league/html-to-markdown` for hybrid use cases. php-diff stands out for its HTML rendering flexibility and Laravel compatibility.
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport