Re: Help with fwrite()
| From: | John Nichel | Date: | Wed, 15 Sep 2004 14:08:35 +0000 |
| Subject: | Re: Help with fwrite() | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-196729@lists.php.net to get a copy of this message | ||
John Holmes wrote:
From: "Nick Wilson" <nick@stylesheet.org>Is keeping this info in a db an option? -- John C. Nichel ÜberGeek KegWorks.com 716.856.9675 john@kegworks.comIm trying to delete a line from a file after having first read the line. The file contains a list or urls, one per new line: like this:[snip]fwrite($f, '', strlen($url2use)); // Where is the "gotha"?Hmmm... how can you write an empty string with a length? If you did something like fwrite($f,str_repeat('x',strlen($url2use)); then you'd overwrite the URL with xxxx, though. You can't just remove part of a file like you remove part of a string. You'll need to read (eventually) the entire file and only write back what you want to keep. Now, you said this could be a very large file, so you don't want to read the whole thing into memory. That's smart, so maybe using a swap file would be handy? Read from file1, if it's a URL you want to keep, then write it to file2. rinse, lather, repeat and at the end rename file2 to file1. This way you're only reading one line at a time into memory. Maybe I'm overlooking another obvious method. If so, someone will pop up. :) ---John Holmes...