PHP fwrite () function
Definition and Usage
fwrite () function writes to an open file.
Function at specified length or read the end of the file (EOF) (whichever comes first), stop running.
If the function is executed successfully, it returns the number of bytes written. If it fails, it returns FALSE.
grammar
fwrite(file,string,length)
参数 | 描述 |
---|---|
file | 必需。规定要写入的打开文件。 |
string | 必需。规定要写入打开文件的字符串。 |
length | 可选。规定要写入的最大字节数。 |
Tips and Notes
Tip: This function is binary safe.(Meaning that the binary data (such as images) and character data can use this function to write.)
Examples
<?php
$file = fopen("test.txt","w");
echo fwrite($file,"Hello World. Testing!");
fclose($file);
?>
$file = fopen("test.txt","w");
echo fwrite($file,"Hello World. Testing!");
fclose($file);
?>
The code above will output:
21
Complete PHP Filesystem Reference Manual