How can the content of a file be displayed and edited in a text window using PHP?

To display and edit the content of a file in a text window using PHP, you can read the file contents, display it in a textarea element within a form, allow the user to edit the content, and then save the changes back to the file.

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

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

$content = file_get_contents($file);
?>

<form method="post">
    <textarea name="content" rows="10" cols="50"><?php echo $content; ?></textarea><br>
    <input type="submit" value="Save">
</form>