3v4l.org

run code in 300+ PHP versions simultaneously
<?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++) { echo(sprintf('Current[%s][%s] = %s'.PHP_EOL, $i, $j, substr($b, $j, $i))); 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));
Output for git.master, git.master_jit, rfc.property-hooks
Current[10][0] = stermastei Current[9][0] = stermaste Current[8][0] = stermast Current[7][0] = stermas Current[6][0] = sterma Current[5][0] = sterm Current[4][0] = ster Current[3][0] = ste Current[2][0] = st Current[1][0] = s string(1) "s"

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
53.57 ms | 401 KiB | 8 Q