php 删除开头文件名的文件,如何使用PHP删除文本文件开头的x行数?

我正在编写一个PHP脚本,该脚本输出一个简单的文本文件日志,记录它执行的操作。当文件达到某个文件大小时,如何使用PHP删除该文件的前几行?

理想情况下,我希望它保留前两行(创建日期/时间为空),从第3行开始删除,并删除X行数量。我已经知道了

filesize()

函数,所以我将使用它来检查文件大小。

日志文本示例:

*** LOG FILE CREATED ON 2008-10-18 AT 03:06:29 ***

2008-10-18 @ 03:06:29 CREATED: gallery/thumbs

2008-10-18 @ 03:08:03 RENAMED: gallery/IMG_9423.JPG to gallery/IMG_9423.jpg

2008-10-18 @ 03:08:03 RENAMED: gallery/IMG_9188.JPG to gallery/IMG_9188.jpg

2008-10-18 @ 03:08:03 RENAMED: gallery/IMG_9236.JPG to gallery/IMG_9236.jpg

2008-10-18 @ 03:08:03 RENAMED: gallery/IMG_9228.JPG to gallery/IMG_9228.jpg

2008-10-18 @ 03:08:03 RENAMED: gallery/IMG_3104.JPG to gallery/IMG_3104.jpg

2008-10-18 @ 03:08:03 RENAMED: gallery/First dance02.JPG to gallery/First dance02.jpg

2008-10-18 @ 03:08:03 RENAMED: gallery/BandG02.JPG to gallery/BandG02.jpg

2008-10-18 @ 03:08:03 RENAMED: gallery/official03.JPG to gallery/official03.jpg

2008-10-18 @ 03:08:03 RENAMED: gallery/Wedding32.JPG to gallery/Wedding32.jpg

2008-10-18 @ 03:08:03 RENAMED: gallery/Gettaway car16.JPG to gallery/Gettaway car16.jpg

2008-10-18 @ 03:08:04 CREATED: gallery/thumbs/Afterparty05.jpg

2008-10-18 @ 03:08:04 CREATED: gallery/thumbs/IMG_9254.jpg

2008-10-18 @ 03:08:04 CREATED: gallery/thumbs/IMG_9175.jpg

2008-10-18 @ 03:08:04 CREATED: gallery/thumbs/official05.jpg

2008-10-18 @ 03:08:04 CREATED: gallery/thumbs/First dance01.jpg

2008-10-18 @ 03:08:04 CREATED: gallery/thumbs/Wedding29.jpg

2008-10-18 @ 03:08:04 CREATED: gallery/thumbs/men walking.jpg

  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

表情包
插入表情
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符
相关推荐
©️2020 CSDN 皮肤主题: 数字20 设计师:CSDN官方博客 返回首页