以相反的顺序读取文件 [英] Reading a file in reverse order

查看:84
本文介绍了以相反的顺序读取文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!


我需要以相反的顺序读取文件(逐行),而不是首先将

整个文件读入内存。


有这么简单的方法吗?在,有没有PHP函数我可以使用?b / b
解决方案必须与平台无关,所以popen(&tac $ filename ;)...

不起作用。


示例输入和输出:


< myfile.txt输入>

第1行

第2行

第3行

< /myfile.txt输入> ;


< php脚本输出>

第3行

第2行

第1行

< /从php脚本输出>

一切顺利,


Erik


-

Erik Andersson(AussieTraders.com.au)
http://www.aussietraders.com.au/

- AussieTraders.com.au,澳大利亚的买入和购买是免费的。出售

marketplace

Hi!

I need to read a file (line-by-line) in reverse order, without reading the
whole file into memory first.

Is there an easy way of doing this? As in, is there a PHP function I could
use?

The solution has to be platform independent, so "popen("tac $filename")...
wouldn''t work.

Example input and ouput:

<myfile.txt input>
line 1
line 2
line 3
</myfile.txt input>

<output from php script>
line 3
line 2
line 1
</output from php script>
All the best,

Erik

--
Erik Andersson ( AussieTraders.com.au )
http://www.aussietraders.com.au/
- Placing an add is FREE at AussieTraders.com.au, Australia''s buy & sell
marketplace

推荐答案

filename")...

无法正常工作。


示例输入和输出:


< myfile.txt输入>

第1行
第2行

第3行

< /myfile.txt输入>


<输出来自php脚本>

第3行

第2行

第1行

< /从php脚本输出>

一切顺利,


Erik


-

Erik Andersson(AussieTraders。 com.au)
http://www.aussietraders.com.au/

- 在AussieTraders.com.au,澳大利亚的买入和购买时免费提供加价。出售

marketplace
filename")...
wouldn''t work.

Example input and ouput:

<myfile.txt input>
line 1
line 2
line 3
</myfile.txt input>

<output from php script>
line 3
line 2
line 1
</output from php script>
All the best,

Erik

--
Erik Andersson ( AussieTraders.com.au )
http://www.aussietraders.com.au/
- Placing an add is FREE at AussieTraders.com.au, Australia''s buy & sell
marketplace


如果文件很小,请将它们加载到数组中
if the files are small, load them into an array


aryFile =

文件(" filename.txt");


然后只需反转数组或读取后缀

-

Mike Bradley
http://www.gzentools.com - 免费在线php工具

" Erik Andersson" < ER ** @ eneit.com>在消息中写道

news:40 ********************* @ uq-127creek-reader-01.brisbane.pipenetworks.com

..au ...
aryFile =
file("filename.txt");

then just reverse the array or read backwords
--
Mike Bradley
http://www.gzentools.com -- free online php tools
"Erik Andersson" <er**@eneit.com> wrote in message
news:40*********************@uq-127creek-reader-01.brisbane.pipenetworks.com
..au...
嗨!

我需要以相反的顺序读取文件(逐行),而不读取将整个文件放入内存中。

有没有简单的方法可以做到这一点?在,有没有我可以使用的PHP函数?

解决方案必须是独立于平台的,所以popen(" tac
Hi!

I need to read a file (line-by-line) in reverse order, without reading the
whole file into memory first.

Is there an easy way of doing this? As in, is there a PHP function I could
use?

The solution has to be platform independent, so "popen("tac

这篇关于以相反的顺序读取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆