logo Php Tutorial
Php Tutorial

File Truncate
Show Myanmar Version
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');

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.

For more detail please see Php Manual at

Processing time -- 0.2293 seconds.