How can HTML code stored in a database be displayed as plain text in PHP?

When HTML code is stored in a database and retrieved in PHP, it may be displayed as rendered HTML rather than plain text. To display it as plain text, you can use the htmlspecialchars() function in PHP to escape the HTML characters and prevent them from being interpreted as code.

<?php
// Retrieve HTML code from database
$htmlCode = "<p>This is some <strong>HTML</strong> code.</p>";

// Display HTML code as plain text
echo htmlspecialchars($htmlCode);
?>