温馨提示×

php fwrite函数的用法是什么

PHP
小亿
82
2024-03-01 12:09:12
栏目: 编程语言

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的文件中。

0