php - file truncate


php - file truncate
As we have mentioned before, when you open a file for writing with the paramater 'w' it completely wipes all data from that file. This action is also referred to as "truncating" a file. Truncate literally means to shorten.

php - file open: truncate

To erase all the data from our testFile.txt file we need to open the file for normal writing. All existing data within testFile.txt will be lost.

PHP Code:

$myFile = "testFile.txt";
$fh = fopen($myFile, 'w');
fclose($fh);

Comments