What are the common methods for saving form data to a file on a server using PHP?

When saving form data to a file on a server using PHP, common methods include using the fopen() function to open a file, fwrite() function to write data to the file, and fclose() function to close the file. It's important to properly sanitize and validate the form data before saving it to prevent security vulnerabilities.

<?php
// Sanitize and validate form data
$data = $_POST['data'];

// Open a file for writing
$file = fopen('data.txt', 'w');

// Write data to the file
fwrite($file, $data);

// Close the file
fclose($file);
?>