I'm collecting data from a form and using it to write to a flat file like so:
Quote:
//this removes line breaks in an text field box and substitutes double breaks
$postbody = str_replace("\r\n", "<br/><br/>",$postbody);
$thepost = "$postitle | $postdate | $postbody | $author \r\n";
if ($posttype=="add") {
// the r+ flag reads and writes at the top of the file, "a" writes at the bottom
$file = fopen("../includes/news.txt", 'r+');
fwrite ($file, "$thepost\r\n");
fclose($file);
}
else { }
I can write to the bottom of the file, no problem, but if I want to put new entries at the top of the file I have problems:
the previous entry is partially overwritten and mangled..
like so: (this is the top line from the text file

Site Redesign | Jan 9, 07, 9:31 am | The site has a new look...etc

becomes

new look!...etc

a 20 character post overwrites 22
a 50 character post overwrites 62
61 character post overwrites 64
260 character post overwrites 260 characters.. it seems to be random, somewhat...
any ideas?

Reply via email to