fwrite writing from beginning without removing
I am using PHP and fwrite code, but I want every write position to start from the beginning of the file without erasing it's content. I am using this code but it is writing to the end of the file. $fr = fopen("aaaa.txt", "a"); fwrite($fr, "text"); fclose($fr); So you want to write at the beginning of a file, leaving all of its current contents after the new data? You'll have to grab its existing contents first, then append it back into the file once you've overwritten with your new data. $file = 'aaaa.txt'; $oldContents = file_get_contents($file); $fr = fopen($file, 'w'); fwrite($fr, "text");