使用 php 删除除前 20 行之外的所有行
如何使用 php 从文本文件中删除除前 20 行之外的每一行?
how to remove every line except the first 20 using php from a text file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
如何使用 php 从文本文件中删除除前 20 行之外的每一行?
how to remove every line except the first 20 using php from a text file?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(5)
如果将整个文件加载到内存中是可行的,您可以这样做:
更好的解决方案是使用函数 ftruncate 获取文件句柄和文件的新大小(以字节为单位),如下所示:
If loading the entire file in memory is feasible you can do:
A better solution would be to use the function ftruncate which takes the file handle and the new size of the file in bytes as follows:
对于内存有效的解决方案,您可以使用
For a memory efficient solution you can use
抱歉,看错问题了...
Apologies, mis-read the question...
像这样的东西:
Something like:
这应该可以在不使用大量内存的情况下工作
This should work as well without huge memory usage