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>
Keywords
Related Questions
- Is it best practice to use a loop to iterate through each day between two specified dates to determine the price range in PHP?
- How can one determine if a server is configured in a way that allows include files to be accessed by others?
- In PHP, what are some common mistakes to avoid when passing values to functions without storing them in variables first?