rupam_jaiswal Posted June 11, 2009 Share Posted June 11, 2009 Hi, Please excuse if similar query has been posted earlier. I have text file in which I have to search a word and replace it with a new word. First I do is to get the file contents with fopen,then read the contents , maintain a string $newcontent that holds the contents of file ,the moment i get my word,replace it with new word in the string $newcontent After that I write the whole string $newcontent to file again. What I want is to just while scanning the file,the moment I find my word,replace it with new word there only instead of rewriting the whole file again. Regards Quote Link to comment https://forums.phpfreaks.com/topic/161804-edit-a-file/ Share on other sites More sharing options...
Adam Posted June 11, 2009 Share Posted June 11, 2009 I'm not totally sure this is possible, with PHP at least. As I picture it in my head (excuse any weak terminology) if you were to overwrite part of the file, you'd be overwriting certain characters / bytes, but obviously if the string was a different length you'd be overwriting the characters next to it, or even leaving some as they were. Effectively you'd have to shuffle all the characters after it into place - which is almost rewriting the file anyway. As I said though this is just how I picture it, I have nothing to back this up. There may well be PHP support for it... I've just never seen or read about it before. How comes it's such an issue? Quote Link to comment https://forums.phpfreaks.com/topic/161804-edit-a-file/#findComment-853781 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.