evanct Posted January 28, 2009 Share Posted January 28, 2009 Okay so I want to open a file and insert some text in the middle of it. but when i fseek to the correct place and then fwrite, it overwrites the current text with the new text. for example if I have the text "abcdefg" in abc.txt and do this: $f=fopen("abc.txt","r+"); fseek($f,1); fwrite($f,"123"); fclose($f); abc.txt would be changed to: a123efg how do I get around this? Link to comment https://forums.phpfreaks.com/topic/142746-solved-fseekfwrite-overwrites-existing-text/ Share on other sites More sharing options...
ratcateme Posted January 28, 2009 Share Posted January 28, 2009 i think you would have to read the entire file and edit it then rewrite the file again with the new data Scott. Link to comment https://forums.phpfreaks.com/topic/142746-solved-fseekfwrite-overwrites-existing-text/#findComment-748252 Share on other sites More sharing options...
evanct Posted January 28, 2009 Author Share Posted January 28, 2009 okay I just used file_get_contents(), divided it into substrings for the start content and end content, then rewrote the file with the new text between $startcontent and $endcontent. simple Link to comment https://forums.phpfreaks.com/topic/142746-solved-fseekfwrite-overwrites-existing-text/#findComment-748261 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.