- substr: documentation ( source)
- var_dump: documentation ( source)
- strpos: documentation ( source)
<?php
function getSimilarSubstring($a, $b)
{
if(!strlen($a) || !strlen($b))
{
return '';
}
if(false!==strpos($a, $b))
{
return $b;
}
$length = strlen($b);
for($i=$length-1; $i>0; $i--)
{
for($j=0; $j<$length-$i; $j++)
{
if($result = getSimilarSubstring($a, substr($b, $j, $i)))
{
return $result;
}
}
}
return '';
}
$word_a = "superman";
$word_b = "stermastein";
//$word_a = 'afk';
//$word_b = 'fk';
var_dump(getSimilarSubstring($word_a, $word_b));