In my understanding, when you use fopen to open a file in r+ the pointer goes at the beginning of the file. So if the original file simply containts the text "message1" and i use the code
$fp= fopen("filename.txt", "r+");
fwrite($fp,"message2\r\n");
fclose();
the file contents should be
message2
message1
as far as i know. i must be missing something.