我有一个名为“B-small-practice.in”的文件,其内容如下
this is a test
foobar
all your base
class
pony along
我写了一个代码,它的功能是反转每一行中的单词并将它们写入另一个文件 "output.txt" 。
这是代码:
$file = fopen("B-small-practice.in", "r");
$lines = array();
while(!feof($file)){
$lines[] = fgets($file);
}
fclose($file);
$output = fopen("output.txt", "a");
foreach($lines as $v){
$line = explode(" ", $v);
$reversed = array_reverse($line);
$reversed = implode(" ", $reversed);
fwrite($output, $reversed."\n");
}
fclose($output);
?>
代码的预期输出将写入“output.txt”以下内容:
test a is this
foobar
base your all
class
along pony
但这就是我得到的:
test
a is this
foobar
base
your all
class
along
pony
是什么让它看起来像这样?