PHP中如何对文件进行反向排序?
我有一个像这样的文本(text.txt)文件:
shir
beer
geer
deer
我还有一个带有该源的php页面:
<?php
foreach (glob("*.txt") as $filename) {
$file = $filename;
$contents = file($file);
$reverse = array_reverse($file, true);
$string = implode("<br>" , $contents);
echo $string;
echo "<br></br>";
}
?>
我希望在php页面中它将显示:
deer
geer
beer
shir
从文件末尾到开头。
谢谢
i have a text (text.txt) file like this:
shir
beer
geer
deer
i have also a php page with that source:
<?php
foreach (glob("*.txt") as $filename) {
$file = $filename;
$contents = file($file);
$reverse = array_reverse($file, true);
$string = implode("<br>" , $contents);
echo $string;
echo "<br></br>";
}
?>
I want that in the php page it will show:
deer
geer
beer
shir
from the end of the file to the beginning.
thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来您正在反转文件名而不是内容。
代替
:
您也可以从脚本中删除临时变量并执行以下操作
Looks like you are reversing the file name and not the contents.
Do
in place of
Also you can remove the temp variables from you script and do:
你的结果是 $contents,没有反向。
Your result was a $contents, without reverse.