2017 © Pedro Peláez
 

library longest-common-substring

PHP implementation of an algorithm to solve the `longest common substring` problem.

image

triun/longest-common-substring

PHP implementation of an algorithm to solve the `longest common substring` problem.

  • Sunday, April 8, 2018
  • by gonzalom
  • Repository
  • 1 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

PHP - Longest Common Substring

PHP implementation of an algorithm to solve the longest common substring problem., (*1)

Latest Version on Packagist Build Status Coverage status Total Downloads The most recent stable version is 2.0.0 ![Software License][ico-license], (*2)

About

PHP-Longest-Common-Subsequence is a PHP implementation of an algorithm to solve the 'longest common substring' problem., (*3)

From Wikipedia - Longest common substring problem:, (*4)

In computer science, the longest common substring problem is to find the longest string (or strings) that is a substring (or are substrings) of two or more strings., (*5)

Installation

Require triun/longest-common-substring package with composer using the following command:, (*6)

composer require triun/longest-common-substring

Usage

Solver

use Triun\LongestCommonSubstring\Solver;

$solver = new Solver();

$stringA = '0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF';
$stringB = '56789AB56789ABCDE56789ABCDE56789AB56789A123456789A';

// calculates the LCSubstring to be '123456789A'
$result = $solver->solve($stringA, $stringB);

Matches solver

use Triun\LongestCommonSubstring\Solver;

$matchSolver = new MatchesSolver();

$stringA = '0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF';
$stringB = '56789AB56789ABCDE56789ABCDE56789AB56789A123456789A';

$matches = $matchSolver->solve($stringA, $stringB);

// calculates the LCSubstring to be '123456789A'
$result = "$matches";

But also can give you the rest of the results which has the same length:, (*7)

var_dump($matches->values());
array:12 [
  0 => "123456789A"
  1 => "56789ABCDE"
  2 => "56789ABCDE"
  3 => "123456789A"
  4 => "56789ABCDE"
  5 => "56789ABCDE"
  6 => "123456789A"
  7 => "56789ABCDE"
  8 => "56789ABCDE"
  9 => "123456789A"
  10 => "56789ABCDE"
  11 => "56789ABCDE"
]

You can use unique to skip duplicated values:, (*8)

var_dump($matches->unique());
array:2 [
  0 => "123456789A"
  1 => "56789ABCDE"
]

Or even more information about the matches, like the input strings indexes:, (*9)

var_dump($matches->values());
array:12 [
  0 => array:3 [
    "value" => "123456789A"
    "length" => 10
    "indexes" => array:2 [
      0 => 1
      1 => 40
    ]
  ]
  1 => array:3 [
    "value" => "56789ABCDE"
    "length" => 10
    "indexes" => array:2 [
      0 => 5
      1 => 7
    ]
  ]
  2 => array:3 [
    "value" => "56789ABCDE"
    "length" => 10
    "indexes" => array:2 [
      0 => 5
      1 => 17
    ]
  ]
  ...
]

Issues

Bug reports and feature requests can be submitted on the Github Issue Tracker., (*10)

Contributing

See CONTRIBUTING.md for information., (*11)

License

This repository is open-sourced software licensed under the MIT license, (*12)

The Versions

08/04 2018

dev-master

9999999-dev https://github.com/Triun

PHP implementation of an algorithm to solve the `longest common substring` problem.

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

08/04 2018

1.0.0

1.0.0.0 https://github.com/Triun

PHP implementation of an algorithm to solve the `longest common substring` problem.

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires