How can PHP file handling functions like fopen() and fwrite() be used to manipulate and save data to a file?

To manipulate and save data to a file using PHP file handling functions like fopen() and fwrite(), you can first open the file using fopen() with a mode that allows writing (e.g., 'w' for write-only). Then, you can use fwrite() to write data to the file. Make sure to close the file using fclose() after writing to ensure that the changes are saved.

$data = "Hello, World!";
$file = fopen("example.txt", "w") or die("Unable to open file!");
fwrite($file, $data);
fclose($file);
echo "Data written to file successfully!";