PHP file_put_contents() Guide
The file_put_contents() function is used to write a string into a file. Its basic usage is:
file_put_contents($filename, $data);
In this case, $filename refers to the path of the file to be written, and $data refers to the string data to be written.
The file_put_contents() function returns the number of bytes written to the file, or false if the writing fails.
Example usage:
$data = "Hello, world!";
$filename = "file.txt";
$result = file_put_contents($filename, $data);
if($result !== false) {
echo "写入成功,共写入 " . $result . " 字节数据。";
} else {
echo "写入失败。";
}
In the example above, the string data “Hello, world!” is written to a file named file.txt and the number of bytes written is displayed.