There seems to be a small bug ahem in the message board, having to do with adding/stripping slashes. For example, the text below should have a backslash before it (should be: "\ntesting", this bug seems to only happen in PHP tags).
\ntesting
I would try using this Perl regular expression:
preg_replace('/<html>.*<\\/div>/si', '', $content);
As well, the other thing I noticed is that you are trying to read the file using a 1024 byte buffer and loop through to the end of the line. That's nice and all, but very C++-ish, but the problem lies in the fact that you are running the regular expression replacement on each individual 1024-byte portion of the file. It's quite possible that the reason it is not working is simply because there is no </div> in the first 1024 bytes of the file, and then when the next 1024 bytes are read, there is not starting <html> for the expression to match.
Try just using the file() function. It will return the entire file into an array. Then you could do this:
$file = file('/path/to/file');
$contents = join("\r\n", $file);
$contents = preg_replace('/<html>.*<\\/div>/si', '', $contents);
That should work. If it doesn't, then I'm lost. As well, if you want to remove everything up to the first </div>, then you need to add a capital 'U' to the /si above. So that it would look like:
$contents = preg_replace('/<html>.*<\\/div>/Usi', '', $contents);
That is because Perl regular expressions are greedy by default, but greediness would cause everything up to the last </div> to be removed. So depending on how you want it to work, add/remove the U to the expression.
For more info on the file() function, or on regular expressions:
http://ca.php.net/manual/en/function.file.php
http://ca.php.net/manual/en/pcre.pattern.modifiers.php
Hope that helps.
-Percy