From: "Nick Wilson" <[EMAIL PROTECTED]>
[snip]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:
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...
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php