What’s the difference between htmlentities() and htmlspecialchars() in php?

htmlspecialchars:  Convert special characters to HTML entities.
htmlentities: Convert all applicable characters to HTML entities.

htmlspecialchars only takes care of <, >, single quote ‘, double quote ” and ampersand. htmlentities translates all occurrences of character sequences that have different meaning in HTML.

<?php
$str = “A ‘quote’ is <b>bold</b>”;
echo htmlentities($str);
echo htmlentities($str, ENT_QUOTES);
?>

 

OUTPUT

A ‘quote’ is &lt;b&gt;bold&lt;/b&gt;
A 'quote' is &lt;b&gt;bold&lt;/b&gt;

//