Possible duplicate:PHP: is there a command that can delete the contents of a file without opening it?
I have a bash script that runs a php file on the command line and sends the results to a text file. for the βnextβ run of the bash script, I want to clear the previous results from the result file.
@Straight. A simple cp /dev/null yourfile in your bash script will take care of this.
cp /dev/null yourfile
file_put_contents will do this.
file_put_contents
file_put_contents('text.txt', null);
Of course, you can also destroy the contents of a file by redirecting it to it and writing something from bash.
You can also truncate the file to a specified size by following these steps:
ftruncate(fopen('text.txt'), 0);
This example will clear it, but 0 can be anything in the range [0 - file size].
Source: https://habr.com/ru/post/885836/More articles:Recovery error output - javaIs chmod 757 safe? - security37signals Highrise.NET (C #) API - c #Where is the βrightβ place to initialize class variables in AS3 - variablesLinearLayout linear click viewer is never called - androidSelect only the numeric part of the row, only if it starts with a numeric value - sqlIn WPF, how can I get the display size of a control before it actually displays? - layoutDynamic_cast problems: the typeid object is not equal, but the name is equal - c ++Send Raw IP packet in C #, all above the ethernet level - c #NAudio Error: "NoDriver calling acmFormatSuggest" - c #All Articles