Friday, 26 September 2014

htmlspecialchars_decode in PHP

PHP htmlspecialchars_decode() function is the opposite of htmlspecialchars().
The PHP htmlspecialchars_decode() function is utilized to change over some predefined HTML entities are converted to characters .
HTML entities that will be decoded are:

  • & becomes & (ampersand)
  • " becomes " (double quote)
  • ' becomes ' (single quote)
  • < becomes < (less than)
  • > becomes > (greater than)

Syntax:

htmlspecialchars_decode (string,quotestyle,character-set)
 
Parameters description:
string : Required. Defines the input string .
quotestyle : Optional. Determine whether to convert  single and double quotes.
The available quote styles are:
  • ENT_COMPAT - Default. Encodes only double quotes
  • ENT_QUOTES - Encodes double and single quotes
  • ENT_NOQUOTES - Does not encode any quotes

Example:

<?php 
$input_str = "Sam &amp; &#039;Jack&#039;";
echo htmlspecialchars_decode($input_str);
echo "<br />";
echo htmlspecialchars_decode($input_str, ENT_QOUTES);
echo "<br />";
echo htmlspecialchars_decode($input_str, ENT_NOQOUTES);
?>

Output:

Sam & 'Jack' 
Sam & 'Jack' 
Sam & 'Jack'

0 comments:

Post a Comment