jfcherng/php-sequence-matcher
PHP 8.4+ longest sequence matcher inspired by Python difflib. Compare strings or arrays to find matching blocks and similarities for diffing, change detection, and text analysis. Lightweight library extracted from php-diff with improvements.
php artisan sequence:diff).difflib.SequenceMismatch)?Levenshtein for short texts + this package for long sequences) work?difflib for edge cases (e.g., Unicode, nested arrays)?SequenceMatcher facade for concise usage (e.g., SequenceMatcher::compare($a, $b)).accessors or mutators to models for automatic similarity scoring.scopeSimilarTo() for model comparisons (e.g., User::similarTo($referenceUser)).saved()/updated() events to log or validate changes.{"similarity": 0.85}).sequence:compare for CLI diffing (e.g., php artisan sequence:compare file1.txt file2.txt).SequenceMatcher::ratio("hello", "hallo")).getSimilarityAttribute()).cache()->remember) or queues for large datasets.Levenshtein (via rubix/ml) for short sequences.difflib).__toString() or toArray()).Str::lower() for consistent comparisons.Carbon::parse() before comparison.composer require jfcherng/php-sequence-matcher
AppServiceProvider):
public function register()
{
$this->app->singleton(SequenceMatcher::class, fn() => new \Jfcherng\SequenceMatcher\SequenceMatcher());
}
$matcher = app(SequenceMatcher::class);
$ratio = $matcher->ratio("Laravel", "Laravul"); // ~0.857
class Post extends Model
{
public function getSimilarityAttribute()
{
return app(SequenceMatcher::class)->ratio($this->content, $this->original_content);
}
}
phpunit.xml or use Laravel’s partialMock.roave/security-advisories for vulnerability alerts.config/sequence-matcher.php:
'threshold' => 0.7, // Minimum ratio to consider a "match"
'cache_enabled' => env('SEQUENCE_MATCHER_CACHE', false),
SequenceMatcher for custom scoring (e.g., override getOpCodes()).Xdebug to identify bottlenecks (e.g., large array comparisons).difflib:
from difflib import SequenceMatcher
print(SequenceMatcher(None, "abc", "abcd").ratio()) # 0.75
cache()->remember('similarity_$key', ...)).How can I help you explore Laravel packages today?