What are some potential pitfalls of storing and outputting HTML content from a database in PHP?

One potential pitfall of storing and outputting HTML content from a database in PHP is the risk of Cross-Site Scripting (XSS) attacks if the input is not properly sanitized. To prevent this, always use htmlspecialchars() or htmlentities() functions to escape the HTML content before outputting it to the browser.

// Retrieving HTML content from the database
$htmlContent = "<p>This is some <strong>HTML</strong> content from the database</p>";

// Escaping HTML content before outputting it
echo htmlspecialchars($htmlContent);