PhpMyanmar.com logo Php Tutorial
Home
Php Tutorial
 Echo
 If

File Truncate
Show Myanmar Version
 show-myanmar-font
Printer Friendly Page

When you open a file for writing with option 'w' it completely wipes all data from that file.

This action is also referred to as "truncating" a file.

Truncate literally means to shorten.

File Open: Truncate

To erase all the data from a file we need to open the file for normal writing.

All existing data within the file will be lost.

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

Truncate: Why Use It

Truncating is most often used on files that contain data that will only be used for a short time.

These type of files are most often referred to as temporary files.

Note
For more detail please see Php Manual at http://www.php.net

Processing time -- 0.0138 seconds.

9c1b2c7f0769ace615f975dcdf4ea17e