The html_special_chars_decode() function is used to convert convert special HTML entities back to characters.
The following are the HTML entities that will be decoded −
& amp; becomes & (ampersand)
& quot; becomes " (double quote)
& #039; becomes ' (single quote)
& lt; becomes < (less than)
& gt; becomes > (greater than)
Syntax
htmlspecialchars_decode(str,flags)
Parameters
str − The string to decode
flags − Specifies how to handle quotes and which document type to use.
The following are the quote styles are −
ENT_COMPAT - Default. Decodes only double quotes
ENT_QUOTES - Decodes double and single quotes
ENT_NOQUOTES - Does not decode any quotes
Additional flags for specifying the used doctype −
ENT_HTML401 - Default. Handle code as HTML 4.01
ENT_HTML5 - Handle code as HTML 5
ENT_XML1 - Handle code as XML 1
ENT_XHTML - Handle code as XHTML
Return
The htmlspecialchars_decode() function returns the converted string.
The following is an example −
Example
<?php $s = "<p>this -> "keyword in programming language</p>\n"; echo htmlspecialchars_decode($s); echo htmlspecialchars_decode($s, ENT_NOQUOTES); ?>
The following is the output −
Output
<p>this -> "keyword in programming language</p> <p>this -> "keyword in programming language</p>