Does anyone have a method of replacing bytes inside a text file at the position determined by doing an fseek() ? - The 'a' mode in fopen() always defaults to appending to the end of file, and there doesn't appear to be any other listed way of, say, replacing a chunk of data in a fixed-record-length text file. - Can I use popen() to achieve this, maybe ? TIA - Chris
Or you could extract the contents into a string, replace the necessary characters and replace the data in the file with the new string!
Thanks, rohan. - Yes, that's what I figured. Using file_get_contents() and explode(). Then adjust the element in the array and use implode() and file_put_contents to restore it. - Trouble with that solution is that you need the file locked for a "long" time doing the overhead work, otherwise someone is reading the old data. If there was a way of simply writing to the middle, you wouldn't need the file at all until you were actually ready to write. - Shame there's no cleaner solution ! (Genuine random record writes to FRL files) - Chris
I'm OK with that, sastro ! The string manipulation stuff doesn't faze me at all. It was the file handling issue. - Like: You have a textfile of, say, "customers". It's fixed record length with delimit by length and padding. One customer changes their email address so you need to swap out that one FL record for another. With random access file writes, using an offset, that's a no-brainer. In PHP, it's a tad more code-heavy. That was all. - Chris