<?php
$fh = fopen("input.txt", "r");
while (!feof($fh)) {
$test = trim(fgets($fh));
echo (nl2br(reversed($test) . "\n"));
if (empty($test) == true) {
break;
}
}
function reversed($test) {
$words = explode(" ", $test);
$reversed = array_reverse($words);
return $testResult = implode(" ", $reversed);
}
fclose($fh);
?>
The above code is going to give you the following results:
Input
Hello world!
Output
world! Hello
$fh = fopen("input.txt", "r");
while (!feof($fh)) {
$test = trim(fgets($fh));
echo (nl2br(reversed($test) . "\n"));
if (empty($test) == true) {
break;
}
}
function reversed($test) {
$words = explode(" ", $test);
$reversed = array_reverse($words);
return $testResult = implode(" ", $reversed);
}
fclose($fh);
?>
The above code is going to give you the following results:
Input
Hello world!
Output
world! Hello
0 Comments:
Post a Comment