PHP fwrite Function: Complete Guide

The fwrite function is used to write data to an open file. Its basic syntax is as follows:

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

Description of parameters:

  1. $handle: A file handle, which is a resource handle returned after opening a file with the fopen function.
  2. $string: the data to be written to the file.
  3. $length: an optional parameter that specifies the maximum number of bytes to write. If not specified, the entire $string will be written to the file.

Original: 我正在看一本很有趣的书。

Paraphrased: I am reading a very interesting book.

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

The example above writes the string “Hello, World!” to a file named example.txt.

bannerAds