Created
September 24, 2014 20:03
-
-
Save gtsifrikas/88c2b97ce10272f6b4a3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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