0) $i = $T[$i]; } } return $i; //<-- changed the return here to return characters matched } /** * This function computes the backtrack table that must * be passed as parameter for OverlappedStringLength(). * @internal * @param string $s The string to calculate the table for. * @return Array */ function ComputeBackTrackTable($s) // O(N) { $T = Array(); $cnd = 0; $pos = 2; $T[0] = -1; $T[1] = 0; $length = strlen($s); while($pos < $length) { if ($s[$pos - 1] == $s[$cnd]) $T[$pos++] = ++$cnd; elseif ($cnd > 0) $cnd = $T[$cnd]; else $T[$pos++] = 0; } return $T; }