您的位置:宽带测速网 > 编程知识 > php fwrite函数的用法是什么

php fwrite函数的用法是什么

2025-06-14 09:02来源:互联网 [ ]

fwrite函数用于向一个打开的文件中写入数据。其基本语法如下:

fwrite ( resource $handle , string $string [, int $length ] ) : int

参数说明:

$handle:文件资源句柄,通过fopen函数打开文件后返回的资源句柄。$string:要写入文件的数据。$length:可选参数,指定要写入的最大字节数。如果未指定,则会将整个$string写入文件。

示例:

$file = fopen("example.txt", "w");$data = "Hello, World!";fwrite($file, $data);fclose($file);

上面的示例将字符串"Hello, World!"写入了名为example.txt的文件中。

PHP