How can PHP be used to interact with the filesystem for saving and loading data?

To interact with the filesystem for saving and loading data in PHP, you can use file handling functions such as fopen, fwrite, and fread. These functions allow you to open a file, write data to it, and read data from it. You can also use functions like file_put_contents and file_get_contents for simpler file operations.

// Save data to a file
$data = "Hello, World!";
$file = fopen("data.txt", "w");
fwrite($file, $data);
fclose($file);

// Load data from a file
$file = fopen("data.txt", "r");
$data = fread($file, filesize("data.txt"));
fclose($file);

echo $data;