html_entity_decode()
function converts HTML entities into characters.
html_entity_decode()
function is the inverse function of htmlentities()
function.
Convert HTML entities to characters:
<?php $str = "<? W3S?h°°|§>" ; echo html_entity_decode ( $str ) ; ?>
The HTML output of the above code is as follows (see the source code):
<! DOCTYPE html > < html > < body > <? W3S ? h ?? ? ?> </ body > </ html >
The browser output of the above code:
<? W3S ? h ?? ? ?>
Convert HTML entities to characters:
<?php $str = "Bill & 'Steve'" ; echo html_entity_decode ( $str , ENT_COMPAT ) ; // Convert only 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 ) ; // No quotation marks are converted ?>
HTML output of the above code (see source code):
< ! DOCTYPE html > < html > < body > Bill & & #039;Steve'<br> Bill & 'Steve' < br > Bill & & 'Steve' < / body > < / html >
The browser output of the above code:
Bill & 'Steve' Bill & 'Steve' Bill & 'Steve'
Convert HTML entities to characters by using Western European character sets:
<?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 (see source code):
< ! DOCTYPE html > < html > < body > My name is ? yvind ? sane . I 'm Norwegian . < / body > < / html >
The browser output of the above code:
My name is ?yvind ?sane. I'm Norwegian.
html_entity_decode ( string , flags , character - set )
parameter | describe |
---|---|
string | Required. Specifies the string to be decoded. |
flags |
Optional. Specifies how to deal with quotes and which document type to use. Available quote types:
Additional flags specifying the type of document used:
|
character-set |
Optional. String value, specifying the set of characters to be used. Allowed values:
Note: In versions prior to PHP 5.4, unrecognized character sets will be ignored and replaced by ISO-8859-1. Since PHP 5.4, unrecognized character sets will be ignored and replaced by UTF-8. |