I just started learning php and I've come across a problem I can't find the solution to anywhere. All I want to do is scan through a file until I read a key string and then write text there. I have been able to scan through the file to the point needed, but when I then write to the file it replaces the text in the buffer as opposed to inserting the text where the file pointer is. I was using fopen and fwrite. Is there maybe some mode for fopen I need to use which I don't know about? I was using r+.