What are the potential pitfalls of using htmlentities() function in PHP?

Using htmlentities() function in PHP can potentially lead to double encoding if the input string is already encoded. This can result in unintended characters being displayed on the webpage. To prevent this issue, you can use the flag ENT_QUOTES to only encode double quotes.

$string = '<a href="https://example.com">Click here</a>';
$encoded_string = htmlentities($string, ENT_QUOTES);
echo $encoded_string;