The "file_put_contents" function in PHP is used to write data to a file. It takes two parameters: the file name or path, and the data to be written.
Here is an example of how to use the "file_put_contents" function:
$data = "Hello, World!"; // Data to be written
$file = "example.txt"; // File name or path
// Write data to the file
file_put_contents($file, $data);
In this example, the string "Hello, World!" is written to the "example.txt" file. If the file does not exist, it will be created. If the file already exists, its contents will be overwritten.
You can also append data to an existing file by using the "FILE_APPEND" flag as the third parameter:
$data = "Hello, again!"; // Data to be appended
$file = "example.txt"; // File name or path
// Append data to the file
file_put_contents($file, $data, FILE_APPEND);
In this case, the string "Hello, again!" will be appended to the existing contents of the "example.txt" file.
上一篇:php时间搓作比较
下一篇:php怎么转格式
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站