Blog : PHP htmlspecialchars_decode() Function

PHP htmlspecialchars_decode() Function

--------------------------------------------------------------------------------
 Complete PHP String Reference
--------------------------------------------------------------------------------

Definition and Usage
The htmlspecialchars_decode() function converts some predefined HTML entities to characters.

HTML entities that will be decoded are:

& becomes & (ampersand)
" becomes " (double quote)
' becomes ' (single quote)
< becomes < (less than)
> becomes > (greater than)
The htmlspecialchars_decode() function is the opposite of htmlspecialchars().

Syntax
htmlspecialchars_decode(string,quotestyle)  

Parameter Description
string Required. Specifies the string to decode
quotestyle Optional. Specifies how to decode single and double quotes.
The available quote styles are:

ENT_COMPAT - Default. Decodes only double quotes
ENT_QUOTES - Decodes double and single quotes
ENT_NOQUOTES - Does not decode any quotes
 


--------------------------------------------------------------------------------

Example 1
$str = "Jane & 'Tarzan'";
echo htmlspecialchars_decode($str);
echo "
";
echo htmlspecialchars_decode($str, ENT_QUOTES);
echo "
";
echo htmlspecialchars_decode($str, ENT_NOQUOTES);
?>  

The browser output of the code above will be:

Jane & 'Tarzan'
Jane & 'Tarzan'
Jane & 'Tarzan'  

If you select "View source" in the browser window, you will see the following HTML:



Jane & 'Tarzan'

Jane & 'Tarzan'

Jane & 'Tarzan'

 


--------------------------------------------------------------------------------

Example 2


$str = "My name is Øyvind Åsane. I'm Norwegian";
echo htmlspecialchars_decode($str, ENT_QUOTES);
?>

 

The browser output of the code above will be:

My name is Øyvind Ã…sane. I'm Norwegian  

If you select "View source" in the browser window, you will see the following HTML:



My name is Øyvind Åsane. I'm Norwegian