It has been explained in the previous lectures that whenever you unlock a file for inscription by using ‘w’, the result will be the removal of prior data. It points out to truncating a used file. It means to make shorten the contents of a file.
File Open and Truncate in PHP
In order to remove the previous data from the file newfle.txt, we have to make it open. So that the data present in it will be erased.
Code of PHP
$fh = fopen($mynewFile, 'w');
Why we use truncate command in PHP?
The command truncate is used for the type of data which can be used for small time period. Such types of files are known as temporary file.
You have made a word processor which can store the data online. The processor stores the data from HTML form in server after every 30 seconds. Our file name is newtemp.txt and it will be getting truncated and up to date with the passage of 30 seconds. It is the best way of using the command truncate.