我正在编写一个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
e-satis.. 20
PHP 5带有大量的迭代器优点:
fwrite($line); ?>
在弄乱fopen时你可以做的事情更清晰,它不会将整个文件保存在内存中,一次只能保存一行,并且你可以插入它并在任何地方重复使用该模式,因为它是完整的OO.
PHP 5带有大量的迭代器优点:
fwrite($line); ?>
在弄乱fopen时你可以做的事情更清晰,它不会将整个文件保存在内存中,一次只能保存一行,并且你可以插入它并在任何地方重复使用该模式,因为它是完整的OO.