目录

PHP fwrite() 函数

❮ PHP 文件系统参考

示例

写入打开的文件:

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

上面代码的输出将是:

21


定义和用法

fwrite() 写入打开的文件。

该函数将在文件末尾 (EOF) 或达到指定长度时停止,以先到者为准。

语法

fwrite( file, string, length)

参数值

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


技术细节

返回值: 写入的字节数,失败时为 FALSE
PHP 版本: 4.0+
二进制安全: 是的

❮ PHP 文件系统参考