How can PHP be used to save form data in a text file and output it as an HTML table?

To save form data in a text file using PHP, you can first retrieve the form data using $_POST, then write it to a text file using file_put_contents(). To output the saved data as an HTML table, you can read the text file, parse the data, and display it within an HTML table structure.

<?php
// Save form data to text file
if(isset($_POST['submit'])){
    $data = $_POST['data'];
    file_put_contents('data.txt', $data . PHP_EOL, FILE_APPEND);
}

// Output saved data as HTML table
$data = file('data.txt');
echo '<table border="1">';
echo '<tr><th>Data</th></tr>';
foreach($data as $line){
    echo '<tr><td>' . $line . '</td></tr>';
}
echo '</table>';
?>