PHP html_entity_decode() function
Example
Convert HTML entities to characters:
<?php $str = "<© W3Sçh°°¦§>"; echo html_entity_decode($str); ?>
The HTML output of the above code is as follows (view source code):
<!DOCTYPE html> <html> <body> <? W3S?h????> </body> </html>
Browser output of the above code:
<? W3S?h????>
Definition and Usage
The html_entity_decode() function converts HTML entities to characters.
The html_entity_decode() function is htmlentities() Inverse function of the function.
Syntax
html_entity_decode(string,flags,character-set)
Parameter | Description |
---|---|
string | Required. Specify the string to be decoded. |
flags |
Optional. Specify how quotes are handled and which document type to use. Available quote types:
Specify additional flags for the document type used:
|
character-set |
Optional. String value, specifying the character set to be used. Allowed values:
Note:In versions of PHP prior to 5.4, unrecognized character sets were ignored and replaced by ISO-8859-1. Starting from PHP 5.4, unrecognized character sets were ignored and replaced by UTF-8. |
Technical details
Return value: | Returns the converted string |
PHP version: | 4.3.0+ |
Update log:
Version | Description |
---|---|
PHP 5 | character-set The default parameter value has been changed to UTF-8. |
PHP 5.4 |
Additional flags have been added to specify the document types for which the translation table is applicable:
|
PHP 5.3.4 | New support for multi-byte encoding added. |
More Examples
Example 1
Convert HTML entities to characters:
<?php $str = "Bill & 'Steve'"; echo html_entity_decode($str, ENT_COMPAT); // Only convert double quotes echo "<br>"; echo html_entity_decode($str, ENT_QUOTES); // Convert double and single quotes echo "<br>"; echo html_entity_decode($str, ENT_NOQUOTES); // Do not convert any quotes ?>
HTML output of the above code (view source code):
<!DOCTYPE html> <html> <body> Bill & 'Steve'<br> Bill & 'Steve'<br> Bill & 'Steve' </body> </html>
Browser output of the above code:
Bill & 'Steve' Bill & 'Steve' Bill & 'Steve'
Example 2
Convert HTML entities to characters using the Western European character set:
<?php $str = "My name is Øyvind Åsane. I'm Norwegian."; echo html_entity_decode($str, ENT_QUOTES, "ISO-8859-1"); ?>
HTML output of the above code (view source code):
<!DOCTYPE html> <html> <body> My name is ?yvind ?sane. I'm Norwegian. </body> </html>
Browser output of the above code:
My name is ?yvind ?sane. I'm Norwegian.