Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP fwrite() Function

PHP fwrite() Function


PHP Filesystem Reference Manual Complete PHP Filesystem Reference Manual


Definition and Usage

The fwrite() function writes content to an open file.

The function stops when it reaches the specified length or the end of file (EOF), whichever comes first.

Returns the number of bytes written on success, or FALSE on failure.

Syntax

fwrite(file,string,length)

Parameters Description
file Required. Specifies the open file to write to.
string Required. Specifies the string to write to the open file.
length Optional. Specifies the maximum number of bytes to write.

Tips and Notes

**Tip:** This function is binary-safe (meaning both binary data, such as images, and character data can be written with this function).


Example

The code above will output:

21


PHP Filesystem Reference Manual Complete PHP Filesystem Reference Manual