PHP抓取txt文件中的最后15行 [英] PHP Grab last 15 lines in txt file

查看:49
本文介绍了PHP抓取txt文件中的最后15行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

感谢您花时间阅读本文,无论内容质量如何,我都会感谢您的每一个回复.:)

Thank you for taking the time to read this and I will appreciate every single response no mater the quality of content. :)

使用 PHP,我试图获取文本文档 (.txt) 的最后 15 行并将该数据存储到 php 变量中.我知道这是可能的,但是当我得到最后 15 行时,是否可以保留顺序?例如:

Using PHP, I'm trying to get the last 15 lines of a text document (.txt) and store that data into a php variable. I understand that this is possible, however when I do get the last 15 lines, is it possible to retain the order? For example:

文本文档:

A
B
C

当我从最后 15 个字符中抓取文本文档时,我不希望回声像这样结束:

When I grab the text document from the last 15 characters, I don't want the echo to end up like:

C
B
A

感谢所有帮助,期待您的回复;谢谢你.:) 如果我没有解释清楚和/或您希望我更详细地解释,请回复.:)

All assistance is appreciated and I look forward to your replies; thank you. :) If I didn't explain anything clearly and/or you'd like me to explain in more detail, please reply. :)

谢谢.

推荐答案

尝试使用 array_slice,它将返回数组的一部分.在这种情况下,您希望它返回数组的最后 15 行,因此:

Try using array_slice, which will return a part of an array. In this case you want it to return the last 15 lines of the array, so:

$filearray = file("filename");
$lastfifteenlines = array_slice($filearray,-15);

这篇关于PHP抓取txt文件中的最后15行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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