What potential pitfalls should be considered when storing and displaying PHP code snippets in a database?

When storing and displaying PHP code snippets in a database, one potential pitfall to consider is the risk of code injection attacks if the input is not properly sanitized. To mitigate this risk, it is important to escape the PHP code snippets before storing them in the database and when displaying them on the website. This can be done using functions like htmlspecialchars() or htmlentities() to prevent malicious code from being executed.

// Sanitize PHP code snippet before storing in the database
$snippet = htmlspecialchars($snippet);

// Display sanitized PHP code snippet on the website
echo htmlentities($snippet);