douaipi3965 2011-01-21 00:34
浏览 326
已采纳

fgets()PHP读取最后一行?

Using the fgets() function (or any other way) in PHP is there a way to read the LAST line of a file then work backwards? What I am doing: (as per request) I am appending to a .txt file lines from an input (don't worry about that) and of course append adds to the END of a file so I need to display the contents of a file with one line being one entry to be displayed
So if the contents of the file are:
Hello, World!
Foo likes Bar!
then it needs to display as
1. Foo likes Bar!
2. Hello, World!

  • 写回答

2条回答 默认 最新

  • duansha6410 2011-01-21 00:38
    关注

    As far as I know PHP does not know the gets() function. But..

    If you use 'file()' and inverse the array you can work it through from bottom to top. That should do the trick for you!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部