使用 file_get_contents 跳行?
我试图跳过前 2 行(从读取 3 个文件中)然后保存回来(我已经完成了此操作,剩下的就是跳过行)
有什么办法可以做到这一点吗?
I'm trying to skip the first 2 lines (from reading 3 files) then save back (I already got this done, all that's left is the line skipping)
Is there any way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是一种方法。也许这有点矫枉过正,因为它效率不高。 (使用
file()
会快得多)This is one way of doing it. Perhaps it's a bit overkill, as it's not very efficient. (using
file()
would be much faster)是的,但是使用 file_get_contents 会太复杂。我建议改用
file()
函数:Yes, but using file_get_contents it would be too complicated. I advise using the
file()
function instead:使用 file(),然后取消设置前 2 个数组键,然后内爆
use file(), then unset the the first 2 array keys then implode
如果行不是很长,您不能在读取文件时使用正则表达式吗?从php手册中,file_get_contents中有一个offset参数,尽管这很可能不会有用,因为那时你需要提前知道行长度。也许 file_get_contents 不是在这种情况下使用的正确函数?
If lines are not very long can't you just use regex on read files? From php manual there is offset parameter in file_get_contents, though this most likely wont be useful since then you need to know line lengths in advance. Maybe file_get_contents isn't proper function to use in this case?