Nothing I know because of the box. but this should do it:
function merge_overlap($left, $right) {
// continue checking larger portions of $right
for($l = 1; $l < strlen($right); $l++) {
// if we no longer have a matching subsection return what left appended
if(strpos($left, substr($right, 0, $l)) === false) {
return $left . substr($right, $l - 1);
}
}
// no overlap, return all
return $left . $right;
}
EDIT: OBO has been updated.
UPDATE: this is not a solution, strpos () matches part of the text anywhere in the left path, should be compared with the tail.
Here is the correct implementation for my approach:
function merge_overlap($left, $right) {
$l = strlen($right);
while($l > 0 && substr($left, $l * -1) != substr($right, 0, $l))
$l--;
return $left . substr($right, $l);
}
source
share