PHP fwrite() Function

Definition and Usage

fwrite() function writes to a file (can be safely used for binary files).

Syntax

fwrite(the content of,string,length)
Parameters Description
the content of Required. Specifies the file to write to.
string Required. Specifies the string to write to the file.
length Optional. Specifies the maximum number of bytes to write.

Description

fwrite() writes string is written to the file pointer the content of If specified lengthwhen written at length bytes or the end of writing string From then on, writing will stop, depending on which condition is encountered first.

fwrite() returns the number of characters written, or false on error.

Example

<?php
$file = fopen("test.txt","w");
echo fwrite($file,"Hello World. Testing!");
fclose($file);
?>

Output:

21