htmlentities() and ENT_QUOTES
In this article I will talk a little about htmlentities() built-in function in PHP and its property "ENT_QUOTES", this function is used to convert all applicable characters to HTML entities, this function is identical to htmlspecialchars() in all ways, except with htmlentities(), all characters which have HTML character entity equivalents are translated into these entities.
If you're wanting to decode instead (the reverse) you can use html_entity_decode().
This function can help us in securing our sites from hackers and mysql injections, it also fixes mysql bugs which can result if we use the single quote as an entry in the insert query.
Let us see some examples :
$str = "A 'quote' is <b>bold</b>";
// Outputs: A 'quote' is <b>bold</b>
echo htmlentities($str);
// // Outputs: A 'quote' is <b>bold</b>
echo htmlentities($str, ENT_QUOTES);
?>
Here you will see that the variable 'str' will have a single quote and <b>bold</b> html tag in it self, when using htmlentities on it, it will output only <> as entities, and ignore the single quote, so we are using another property in htmlentities "ENT_QUOTES", the function will not ignore the single quote in this case, that will solve our problem with this function.
For any questions please comment ...
