How can PHP be used to send form data to a server and save it in a file?

To send form data to a server and save it in a file using PHP, you can create a PHP script that receives the form data via POST method, processes it, and then saves it to a file on the server. You can use the $_POST superglobal array to access the form data and file_put_contents() function to save it to a file.

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $data = $_POST['data'];
    $file = 'data.txt';
    file_put_contents($file, $data, FILE_APPEND);
    echo "Data saved successfully!";
}
?>