Longest string challenge: Difference between revisions
Content added Content deleted
mNo edit summary |
|||
Line 1,507: | Line 1,507: | ||
?longest(0)</lang> |
?longest(0)</lang> |
||
=={{header|PHP}}== |
|||
<lang PHP><?php |
|||
echo 'Enter strings (empty string to finish) :', PHP_EOL; |
|||
$output = $previous = readline(); |
|||
while ($current = readline()) { |
|||
$p = $previous; |
|||
$c = $current; |
|||
// Remove first character from strings until one of them is empty |
|||
while ($p and $c) { |
|||
$p = substr($p, 1); |
|||
$c = substr($c, 1); |
|||
} |
|||
// If $p and $c are empty : strings are of equal length |
|||
if (!$p and !$c) { |
|||
$output .= PHP_EOL . $current; |
|||
} |
|||
// If $c is not empty, $current is longer |
|||
if ($c) { |
|||
$output = $previous = $current; |
|||
} |
|||
} |
|||
echo 'Longest string(s) = ', PHP_EOL, $output, PHP_EOL;</lang> |
|||
{{out}} |
|||
<pre>Enter strings (empty string to finish) : |
|||
a |
|||
bb |
|||
ccc |
|||
ddd |
|||
ee |
|||
f |
|||
ggg |
|||
Longest string(s) = |
|||
ccc |
|||
ddd |
|||
ggg</pre> |
|||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |