PHP html_entity_decode()Functions
Examples
Convert HTML entities to characters:
$str = "<© W3CSçh°°¦§>";
echo html_entity_decode($str);
?>
The HTML output of the above code is as follows (view source code):
<html>
<body>
<© W3CSçh°°¦§>
</body>
</html>
The browser output of the above code is as follows:
Definition and Usage
The html_entity_decode() function converts HTML entities to characters.
The html_entity_decode() function is thehtmlentities()inverse function of the function.
Syntax
| Parameters | Description |
|---|---|
| string | Required. Specifies the string to be decoded. |
| flags | Optional. Specifies how to handle quotes and which document type to use. Available quote types:
Additional flags specifying the document type to use:
|
| character-set | Optional. A string that specifies the character set to use. Allowed values:
Note:In versions before PHP 5.4, unrecognized character sets were ignored and replaced by ISO-8859-1. As of PHP 5.4, unrecognized character sets are ignored and replaced by UTF-8. |
Technical Details
| Return value: | Returns the converted string. |
|---|---|
| PHP Version: | 4.3.0+ |
| Changelog: | In PHP 5,character-setthe default value of the parameter was changed to UTF-8. In PHP 5.4, additional flags for specifying the document type to use were added: ENT_HTML401, ENT_HTML5, ENT_XML1, and ENT_XHTML. In PHP 5.0, support for multibyte encodings was added. |
More Examples
Example 1
Convert some HTML entities to characters:
$str = "Jane & 'Tarzan'";
echo html_entity_decode($str, ENT_COMPAT); // Will only convert double quotes
echo "<br>";
echo html_entity_decode($str, ENT_QUOTES); // Converts double and single quotes
echo "<br>";
echo html_entity_decode($str, ENT_NOQUOTES); // Does not convert any quotes
?>
The HTML output of the above code is as follows (view source code):
<html>
<body>
Jane & 'Tarzan'<br>
Jane & 'Tarzan'<br>
Jane & 'Tarzan'
</body>
</html>
The browser output of the above code is as follows:
Jane & 'Tarzan'
Jane & 'Tarzan'
Example 2
Convert some HTML entities to characters by using the Western European character set:
$str = "My name is Øyvind Åsane. I'm Norwegian.";
echo html_entity_decode($str, ENT_QUOTES, "ISO-8859-1");
?>
The HTML output of the code above will be (View Source):
<html>
<body>
My name is Øyvind Åsane. I'm Norwegian.
</body>
</html>
The browser output of the above code is as follows:
PHP String Reference Manual Other Extensions