PHP fwrite() Function

❮ PHP Filesystem Reference

Example

Write to an open file:

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

The output of the code above will be:

21


Definition and Usage

The fwrite() writes to an open file.

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

Syntax

fwrite(file, string, length)

Parameter Values

Parameter 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


Technical Details

Return Value: The number of bytes written, FALSE on failure
PHP Version: 4.0+
Binary Safe: Yes

❮ PHP Filesystem Reference
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.