drifter Posted January 11, 2007 Share Posted January 11, 2007 is there a way to delete a line from a file without rewriting it?I have a 300K file with about 20000 lines - each line takes about 1.5 seconds to process. (images and such)the problem is, this runs for hours - then it fails and It starts over.I would like to remove a line on sucess so that the next time it runs it does not rerun the same lines.rewriting the file that large, that many times seems like it would be really hard on the server.ThanksScott Quote Link to comment https://forums.phpfreaks.com/topic/33780-delete-line/ Share on other sites More sharing options...
Daniel0 Posted January 11, 2007 Share Posted January 11, 2007 This should do what you want: [code]<?php$line_number = 135;$filename = "something.txt";$lines = file($filename);unlink($linenumber-1);file_put_contents($filename,implode("\n",$lines));?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/33780-delete-line/#findComment-158497 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.