How can a textarea be used to update the content of a text file in PHP?

To update the content of a text file using a textarea in PHP, you can create a form with a textarea input where users can input the new content. Upon form submission, you can use PHP to read the content from the textarea and write it to the text file.

<?php
if(isset($_POST['content'])) {
    $content = $_POST['content'];
    $file = fopen("file.txt", "w");
    fwrite($file, $content);
    fclose($file);
    echo "Content updated successfully!";
}
?>

<form method="post">
    <textarea name="content"></textarea>
    <input type="submit" value="Update Content">
</form>