Download the PHP package sitefinitysteve/php-diff-text without Composer
On this page you can find all versions of the php package sitefinitysteve/php-diff-text. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sitefinitysteve/php-diff-text
More information about sitefinitysteve/php-diff-text
Files in sitefinitysteve/php-diff-text
Package php-diff-text
Short Description PHP library to generate HTML diff output with multiple diff strategies. PHP variant of vue-diff-text.
License MIT
Informations about the package php-diff-text
php-diff-text
PHP library to generate HTML diff output with multiple diff strategies. Zero external dependencies.
This is a PHP variant of vue-diff-text, a Vue 3 plugin for displaying text and HTML differences. Same diff strategies, same HTML output, same CSS classes — just in PHP.
Author: Steve McNiven-Scott
Installation
That's it — Composer's autoloader handles the rest. No service providers, no config files.
Usage
Each diff class takes old and new text and returns HTML with .diff-added and .diff-removed spans.
Quick start (any PHP project)
Or use the individual classes directly:
Laravel Blade example
In your controller:
In your Blade template:
Tip: Copy
vendor/sitefinitysteve/php-diff-text/css/style.cssintopublic/vendor/php-diff-text/style.css, or add it to your Vite/Mix pipeline.
Output:
Available Diff Classes
| Class | Description |
|---|---|
DiffChars |
Character-level diff |
DiffWords |
Word-level diff (ignores whitespace) |
DiffWordsWithSpace |
Word-level diff (whitespace-aware) |
DiffLines |
Line-level diff |
DiffSentences |
Sentence-level diff |
DiffHtml |
HTML-aware diff with optional similarity threshold |
All methods are static — no instantiation needed.
DiffText Facade
The DiffText class is the recommended entry point:
Options
All text diff classes accept an options array:
HTML Diff with Similarity Threshold
DiffHtml supports a similarity threshold (0-1). When the texts are less similar than the threshold, it renders a "full replacement" instead of a granular diff:
Similarity Utility
Compute text similarity directly:
Styling
Include the bundled CSS for default diff styling:
Or copy it into your asset pipeline. Customize with CSS variables:
Testing
Publishing to Packagist
First-time setup
-
Create a GitHub repository:
-
Register on Packagist:
- Log in with your GitHub account
- Click "Submit" and enter the GitHub repo URL
- Packagist will auto-detect the
composer.json
- Set up auto-updating (recommended):
- On Packagist, go to your package settings and grab the API token
- On GitHub, go to repo Settings > Webhooks > Add webhook
- Payload URL:
https://packagist.org/api/github?username=sitefinitysteve - Content type:
application/json - Secret: your Packagist API token
- Events: "Just the push event"
Releasing a new version
Tag a release and push:
Or use GitHub Releases:
Packagist picks up the new tag automatically via the webhook.
GitHub Actions (optional auto-test on release)
Create .github/workflows/tests.yml:
License
MIT
Made with ❤️ by sitefinitysteve