hey, I have a large file and I want to keep the last x row of it.  I 
figured out how to navigate to the point where I want to extract the 
data, but I cant figure out how to extact from the file current $fp and 
write out the data to another file.
Think of it like this, when the file gets to be x bytes, get the last 20 
lines from it and copy it to another file, so that I could dump the old 
and replace it witht the new....
Thanks.


<--snip of example code-->
$fp = fopen("./chat/chat.txt", "r+");
$size = filesize("chat/chat.txt");
$count = 0;
while (!@feof($fp)) {
         $lines = fgets($fp, 4096);
         $count = $count + 1;
}
$count--; // return the correct # of lines in file
echo "Lines: $count<br>";
$offset = round($count - ($count / 4));
echo "Offset: $offset<br>";

$count = 0;
rewind($fp);
while ($count < $offset) {
         $lines = fgets($fp, 4096);
         $count = $count + 1;
}
echo "New Offset: $count<br>";
$file = fread($fp);
if (!copy($file, $file.'.bak')) {
     print ("failed to copy $file...<br>\n");
}

fclose($fp);


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to