Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gtsifrikas/88c2b97ce10272f6b4a3 to your computer and use it in GitHub Desktop.
Save gtsifrikas/88c2b97ce10272f6b4a3 to your computer and use it in GitHub Desktop.
function intersect_str($left, $right)
{
$str1 = str_split($left);
$str2 = str_split($right);
$number_of_common_characters = 0;
$len1 = count($str1);
$len2 = count($str2);
for ($i = 0; $i < ($len1 > $len2 ? $len2 : $len1); $i++) {
if (substr($left, $len1 - 1 - $i, $i + 1) == substr($right, 0, $i + 1)) {
$number_of_common_characters = $i + 1;
}
}
return $left . substr($right, $number_of_common_characters, $len2 - $number_of_common_characters);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment