PHP code example of triun / longest-common-substring

1. Go to this page and download the library: Download triun/longest-common-substring library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

triun / longest-common-substring example snippets


use Triun\LongestCommonSubstring\Solver;

$solver = new Solver();

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

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

use Triun\LongestCommonSubstring\Solver;

$matchSolver = new MatchesSolver();

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

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

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

var_dump($matches->values());

var_dump($matches->unique());

var_dump($matches->values());

array:2 [
  0 => "123456789A"
  1 => "56789ABCDE"
]