Re: Help with fwrite()
| From: | John Holmes | Date: | Wed, 15 Sep 2004 14:11:28 +0000 |
| Subject: | Re: Help with fwrite() | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-196727@lists.php.net to get a copy of this message | ||
From: "Nick Wilson" <nick@stylesheet.org>
Im 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...