PHP » I/O » fwrite()

Syntax:
int fwrite(int file, string data [, int length])
file
The file handle of the file to write to.
data
String containing the data that should be written.
length
Number of bytes to write.

Writes to a file.

fwrite() writes data to a file. If a length is specified, that is the maximum number of bytes written. Otherwise, the whole string will be written. The number of bytes written is returned, or false if an error occurred.

Examples

Code:
<?php

$filename = "dummy.txt";

$logfile = fopen($filename, "w");
$nwritten = fwrite($logfile, "This is some data");

print "$nwritten bytes were written to the file";

?>
Output:
17 bytes were written to the file
Explanation:

This code writes to a file and prints how many bytes were written.

See Also: