RSS Amplifier

Gordon Lesti – Personal blog · Oct 16, 2019

Longest common subsequence calculation in PHP with UTF-8 strings

0
Sign in to vote or save

Gordon Lesti · gordonlesti.com

Oct 17, 2019 PHP

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.

Install gordonlesti/longest-common-subsequence

You can find the small library at Github.

Requirements

The library requires PHP 7.

Composer

The recommended installtion is via Composer.

composer require gordonlesti/longest-common-subsequence

Usage

Use GordonLesti\LongestCommonSubsequence\LongestCommonSubsequence.

use GordonLesti\LongestCommonSubsequence\LongestCommonSubsequence;

Calculate the length of the longest common subsequence of two strings.

$lcsDist = LongestCommonSubsequence::lcs("DABDC", "CBDBBAC");

UTF-8 support

The library supports UTF-8.

$lcsDist = LongestCommonSubsequence::lcs("ΛΕΡΒΗΔΟΗΜΑΕΞΞΘΒΗ", "ΗΝΞΛΒΑΚΛ");

Read the original on gordonlesti.com

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.