for ($i = $b0; $i < $b0 + mb_strlen($search_area) && $i < strlen($btext); $i += STEP_SIZE) { // searching for matching text pices with minimum length in current text fragment $offset = 0; while (false !== ($pos = mb_strpos($search_area, mb_substr($btext, $i, STEP_SIZE), $offset))) { // we found the fragment, now we try to grow it $cell = new Cell($atext, $btext, $a0 + $pos, $i, STEP_SIZE); $cell->expand(); if ($cell->getSize() >= MIN_NEEDLE_SIZE && !isset($cells[$cell->getId()])) { $cells[$cell->getId()] = $cell; } $offset = $pos + 1; } } $graph = new Graph($cells); $cells = array(); foreach ($graph->getLongestPaths() as $path) { $cells[] = $chain = new Chain($path); } if ($a0 + SEARCH_AREA_SIZE >= mb_strlen($atext)) { // BEST CHAIN $chain = array_shift($cells); break; } elseif ($a0 == $chain->a2 || !$chain) { $a0 = $a0 + (int) floor(SEARCH_AREA_SIZE / 2); $b0 = $b0 + (int) floor(SEARCH_AREA_SIZE / 2); continue; } $a0 = $chain->a2 - (int) floor(SEARCH_AREA_SIZE / 4); $b0 = $chain->b2 - (int) floor(SEARCH_AREA_SIZE / 4); echo floor($a0 / strlen($atext) * 1000) / 10 . "%\n"; }