Is there any way to remove the contents of an file in php, do we have any php command that does that, I know unlink
but I do not want to delete the file instead
I don't know have you write the contents into the file, but if you use fopen
and you empty the file first, you are basically doing what the w
mode is doing anyway.
From the documentation:
'w': Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.
So I really see no need in emptying it first as you probably will use the w
mode anyway.
You should only empty it if your code relies on the fact that this file is empty or if it is somehow security relevant.