Example
Write to an open file:
html
<?php
$file = fopen("test.txt","w");
echo fwrite($file,"Hello World. Testing!");
fclose($file);
?>
The output of the code above will be:
text
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
text
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 and an E_WARNING on failure |
|---|---|
| PHP Version: | 4.0+ |
| Binary Safe: | Yes |
| Changelog: | PHP 8.0: length is nullable now |