PHP htmlspecialchars() Function

htmlspecialchars(string, quotestyle, character-set ) — Convert special characters to HTML entities. The special characters are:

  • & (ampersand) becomes '&'
  • " (double quote) becomes '"'
  • ' (singe quote) becomes '''
  • < (less than) becomes '&lt;'
  • > (greater than) becomes '&gt;'

htmlentities(string, quotestyle, character-set ) — Very similar to htmlspecialchars() function. However, this function all applicable characters having HTML character entity equivalents are translated into these entities.

Try it here. Enter your string below:

This demonstration using the ENT_QUOTES style with
the default character set of ISO-8859-1.
e.g. An input of Jane & 'Tarzan' will produce
Jane &amp; &#039;Tarzan&#039;

Function Result
Test String:
Use the view source feature of your browser
to see the actual HTML output results.
htmlspecialchars() Result:
htmlentities() Result: