I am trying to write a value of a random ID received from a third party website by JSON decode. I am using following code.
$myFile = "trID.txt";
$myFileLink = fopen($myFile, 'a');
$newContents = $TrID."\n";
fwrite($myFileLink, $newContents);
fclose($myFileLink);
The problem is it is giving a line break above every entry due to unknown reason. If I use 'w' instead of 'a', the file remains blank. Basically i will prefer 'w' as i need to overwrite each entry. The result file is like this.
345435454545
454545454455
345454354354
676767676767
I was suggested This link but it does not remove white space above the ID value while writing to the file. Still getting blank file if i use 'w' in code because first value is always a line break.