PHP ftruncate() Function

PHP ftruncate Function


Definition :

The PHP ftruncate() function truncates an open file to the specified length.

Syntax

 ftruncate(filesize)

Parameter 
Parameter Description
file Required. Specifies the open file to truncate
size Required. Specifies the new file size

Example:

Lets assume that we have a file called demo.txt. This file contains following content:

This is a demo file.
It contains dummy content.

In the example below, the content of the file is displayed before and after truncating its content.

Output :

This is a demo file. It contains dummy content.
This is a demo