How can one ensure that text content from a database is properly displayed on a website in PHP?

To ensure that text content from a database is properly displayed on a website in PHP, you need to make sure that the text is properly escaped to prevent any potential security vulnerabilities such as SQL injection attacks. This can be done using functions like htmlentities() or htmlspecialchars() to encode the text before displaying it on the website.

<?php
// Retrieve text content from the database
$text = $row['content'];

// Escape the text content before displaying it on the website
echo htmlentities($text);
?>