I needed a PHP library that compares strings with a Longest common subsequence algorithm. Important was the support of UTF-8 or Multibyte Strings at all.
You can find the small library at Github.
The library requires PHP 7.
The recommended installtion is via Composer.
composer require gordonlesti/longest-common-subsequence
Use GordonLesti\LongestCommonSubsequence\LongestCommonSubsequence
.
use GordonLesti\LongestCommonSubsequence\LongestCommonSubsequence;
Calculate the length of the longest common subsequence of two strings.
$lcsDist = LongestCommonSubsequence::lcs("DABDC", "CBDBBAC");
The library supports UTF-8.
$lcsDist = LongestCommonSubsequence::lcs("ΛΕΡΒΗΔΟΗΜΑΕΞΞΘΒΗ", "ΗΝΞΛΒΑΚΛ");