<?php

echo 'Enter strings (empty string to finish):', PHP_EOL;

$output = $previous = readline();
while ($current = readline()) {
    $p = $previous;
    $c = $current;
    
    while ($p and $c) {
        $p = substr($p, 1);
        $c = substr($c, 1);
    }
    
    if (!$p and !$c) {
        $output .= PHP_EOL . $current;
    }
    
    if ($c) {
        $output = $previous = $current;
    }
}

echo 'Longest string(s) = ', PHP_EOL, $output, PHP_EOL;