3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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(false!==strpos($a, $result = substr($b, $j, $i))) { return $result; } } } return ''; } $word_a = "ermastsuperman"; $word_b = "stermastein"; var_dump(getSimilarSubstring($word_a, $word_b));
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.13.2, 7.0.0 - 7.1.0
string(6) "ermast"