How can HTML code be displayed in a text window within a form when retrieving a variable from a database in PHP?
To display HTML code in a text window within a form when retrieving a variable from a database in PHP, you can use the htmlspecialchars() function to escape the HTML characters and prevent them from being rendered as code. This will ensure that the HTML code is displayed as plain text within the text window.
<?php
// Retrieve the variable from the database
$html_code = "<h1>Hello, world!</h1>";
// Escape HTML characters using htmlspecialchars() function
$escaped_html = htmlspecialchars($html_code);
// Display the escaped HTML code in a text window within a form
echo '<textarea>' . $escaped_html . '</textarea>';
?>