htmlspecialchars()

It converts predefined characters to HTML entities.  The predefined characters are:

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

Example

<?php
 echo htmlspecialchars("<a href='http://phpcodez.comt'>phpcode</a>");
 ?>

Output

<a href=’http://phpcodez.comt’>phpcode</a>

Share