How can PHP be used to load, edit, and update a .txt file in a textarea?

To load, edit, and update a .txt file in a textarea using PHP, you can use file_get_contents() to load the content of the file into the textarea, allow the user to edit the content, and then use file_put_contents() to update the file with the new content.

<?php
$file = 'example.txt';

if(isset($_POST['content'])) {
    $content = $_POST['content'];
    file_put_contents($file, $content);
}

$text = file_get_contents($file);
?>

<form method="post">
    <textarea name="content"><?php echo $text; ?></textarea>
    <input type="submit" value="Save">
</form>