<?php
// now the only problem with this is, it accesses the file twice
// but i don't see any other way of doing it, please enlighten me.
$filename = 'test.txt';
$somecontent = "new guestbook entry";
// open file for reading
$handle = @fopen($filename, 'r')
or die("file not found");
while ($line = @fgets($handle, 1024)) {
// concatenate it
$somecontent .= $line;
}
fclose($handle);
// open file for writing
$handle = @fopen($filename, 'w')
or die("file not found or not writable");
// do the business
fwrite($handle, $somecontent);
fclose($handle);
?>