What is the difference between htmlspecialchars() and htmlentities() in PHP?

htmlspecialchars() :-

htmlspecialchars() only takes care of predefined characters <, >, single quote ‘, double quote ” and ampersand(&), and converts these characters in to html entities.

  1. < less than convert into &lt;
  2. > greater than convert into &gt;
  3. single quote convert into &#039;
  4. “ double quote convert into &quot;
  5. & ampersand convert into &amp;

htmlentities() :-

htmlentities() translates all occurrences of character sequences that have different meaning in HTML.

Both functions are used to encode user input on a website so that users cannot insert harmful HTML codes into a site.

Leave a Reply

Your email address will not be published. Required fields are marked *

1 × two =

Scroll to top