I am trying to find a method of overwriting (rather than appending) portions of similar text to a .txt file. I have an html user interface (Config) that uses a form to submit various bits of data to a php script that then writes a summary of this data to a .txt file that is read by another html script (Data Viewer) and displayed on a second user interface. There are occasions when the same data IDs will be written to the .txt file by the Config script, however, the Data Viewer GUI always reads the first instance of this data so misses the latest update. I don't really want to clear the whole text file when i hyperlink between the two GUIs if I can help it but I can't seem to find anywhere that explains how to overwrite text in a .txt file, they all seem to append. Below is a sample of the .txt file.
Analogue Output Channels: AN1_OUT,10,0,0,AN3_OUT,45,0,0,0,0,0,0,0,0,0,0,
Analogue Output Channels: AN1_OUT,10,0,0,AN3_OUT,45,0,20,0,0,0,0,0,0,0,0,
Analogue Output Channels:
AN1_OUT,10,AN2_OUT,0,AN3_OUT,45,AN4_OUT,20,AN5_OUT,0,AN6_OUT,0,AN7_OUT,0,AN8_OUT,0,
Analogue Output Channels:
AN1_OUT,0,AN2_OUT,10,AN3_OUT,45,AN4_OUT,20,AN5_OUT,12,AN6_OUT,15,AN7_OUT,23,AN8_OUT,17,
Analogue Output Channels:
AN1_OUT,0,AN2_OUT,10,AN3_OUT,45,AN4_OUT,20,AN5_OUT,12,AN6_OUT,15,AN7_OUT,23,AN8_OUT,17,
Analogue Output Channels:
AN1_OUT,1,AN2_OUT,10,AN3_OUT,45,AN4_OUT,20,AN5_OUT,12,AN6_OUT,15,AN7_OUT,23,AN8_OUT,17,
The write is pretty basic in the php script:
$fp = fopen("Log.txt","a");
fwrite($fp, "Analogue Output Channels: ");
fwrite($fp, "$var5,");
The writing of the variables is placed in a loop so the above is not the full code listing. Any advice would be appreciated.