PHP fwrite() function
Definition and usage
fwrite() function writes to the file (can be safely used for binary files).
Syntax
fwrite(file,string,length)
Parameters | Description |
---|---|
file | 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 content is written to the file pointer file . If specified length, when written length bytes or write finished string From now on, writing will stop, depending on which condition is encountered first.
fwrite() returns the number of characters written, or false if an error occurs.
Example
<?php $file = fopen("test.txt","w"); echo fwrite($file,"Hello World. Testing!"); fclose($file); ?>
Output:
21