What PHP functions can be used to open, write, read, and close a file for data storage?
To open, write, read, and close a file for data storage in PHP, you can use the following functions: 1. fopen() - to open a file 2. fwrite() - to write data to a file 3. fread() - to read data from a file 4. fclose() - to close the file Here is an example code snippet that demonstrates how to use these functions:
<?php
// Open a file for writing
$file = fopen("data.txt", "w");
// Write data to the file
fwrite($file, "Hello, World!");
// Close the file
fclose($file);
// Open the file for reading
$file = fopen("data.txt", "r");
// Read data from the file
$data = fread($file, filesize("data.txt"));
echo $data;
// Close the file
fclose($file);
?>