$start = explode(' ', 'кораблик плавал плавал и утонул');
for ($i = 0, $result = array(), $_result = array(), $length = count($start); $i <= $length; $i++) {
for ($j =0; $j < $i; $j++) {
$stroke = join(' ', array_slice($start, $j, $j + $length - $i + 1));
if (!isset($_result[$stroke])) {
$_result[$stroke] = array_push($result, $stroke);
}
}
}
echo join('<br>', $result);