Computing Magazine

Htmlspecialchar() Function

Posted on the 15 April 2012 by In7rud3r

 

The htmlspecialchar() is the php function which is used to convert predefined characters like &,”,< etc. to HTML entities.

htmlspecialchar() Function

Some of the predefined characters are:

  1. & (ampersand) becomes &amp;
  2. ” (double quote) becomes &quot;
  3. ‘ (single quote) becomes &#039;
  4. < (less than) becomes <
  5. > (greater than) becomes >

For Eg:

<?php
$new = htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES);
echo $new;
?>
OutputTest<a 


Back to Featured Articles on Logo Paperblog

Magazine