<?php
function matchingSubstrings($str1, $str2, $minlen=2) {
$grupos = [];
for($i=1; $i<strlen($str1); $i++) { }
$palavras = [];
$temp = '';
$i = 0;
$j = 0;
do {
if($k = strpos($str2, $grupos[$i], $j) !== false) { $j += $k;
$temp .= $temp === '' ?
$grupos[$i] : substr($grupos[$i], -1); } else {
$temp = '';
$j = 0;
}
$i++;
} while($i<count($grupos));
return $palavras;
}
print_r(matchingSubstrings
('nnnabcnnnabcnnn', 'kkkabckkkabc')); print_r(matchingSubstrings
('asdasdasdTESTEasdasdasdasd', 'lkijlikjTESTEilkjik')); print_r(matchingSubstrings
('asdFINALasdasdTESTEaTESTE2sdasdasdasdTESTENOFINAL', 'lkiTESTE2jlikjTESTEilkjTESikTESTENOFINALjhfdgkFINAL')); print_r(matchingSubstrings
('asdaTSCsdasdTESTEasdasdasdasd', 'lkijlikjTESTEilkjTSCik'));
?>
PD9waHAKZnVuY3Rpb24gbWF0Y2hpbmdTdWJzdHJpbmdzKCRzdHIxLCAkc3RyMiwgJG1pbmxlbj0yKSB7CiAgICAkZ3J1cG9zID0gW107CiAgICBmb3IoJGk9MTsgJGk8c3RybGVuKCRzdHIxKTsgJGkrKykgewogICAgICAgIGFycmF5X3B1c2goJGdydXBvcywgc3Vic3RyKCRzdHIxLCAkaS0xLCAkbWlubGVuKSk7CiAgICB9CgogICAgJHBhbGF2cmFzID0gW107CiAgICAkdGVtcCA9ICcnOwogICAgJGkgPSAwOwogICAgJGogPSAwOwogICAgCiAgICBkbyB7CiAgICAgICAgaWYoJGsgPSBzdHJwb3MoJHN0cjIsICRncnVwb3NbJGldLCAkaikgIT09IGZhbHNlKSB7CiAgICAgICAgICAgICRqICs9ICRrOwogICAgICAgICAgICAkdGVtcCAuPSAkdGVtcCA9PT0gJycgPyAkZ3J1cG9zWyRpXSA6IHN1YnN0cigkZ3J1cG9zWyRpXSwgLTEpOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGlmKCR0ZW1wICE9PSAnJykgYXJy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