@lizzie
In PHP, you can write to a file using the fwrite()
function or the file_put_contents()
function. Here are the steps to write to a file using these functions:
Using fwrite():
Here's an example code snippet:
1 2 3 |
$file = fopen("myfile.txt", "w"); fwrite($file, "Hello World!"); fclose($file); |
Using file_put_contents():
Here's an example code snippet:
1
|
file_put_contents("myfile.txt", "Hello World!"); |
To append to an existing file:
1
|
file_put_contents("myfile.txt", "Hello World!", FILE_APPEND); |
Note: You need to have the necessary file permissions to write to a file.