PHP html_entity_decode () function
Examples
The HTML into character entities:
$str = "<© W3CSçh°°¦§>";
echo html_entity_decode($str);
?>
HTML output of the code above is as follows (view source):
<html>
<body>
<© W3CSch°°¦§>
</body>
</html>
Browser output of the code above is as follows:
Definition and Usage
html_entity_decode () function to HTML entities to characters.
html_entity_decode () function is the htmlentities () inverse function of the function.
grammar
参数 | 描述 |
---|---|
string | 必需。规定要解码的字符串。 |
flags | 可选。规定如何处理引号以及使用哪种文档类型。 可用的引号类型:
规定使用的文档类型的附加 flags:
|
character-set | 可选。一个规定了要使用的字符集的字符串。 允许的值:
注释:在 PHP 5.4 之前的版本,无法被识别的字符集将被忽略并由 ISO-8859-1 替代。自 PHP 5.4 起,无法被识别的字符集将被忽略并由 UTF-8 替代。 |
technical details
return value: | Returns the converted string. |
---|---|
PHP version: | 4.3.0+ |
Update log: | In PHP 5, default value character-set parameters to UTF-8. In PHP 5.4, add the requirement to use additional flags for the document type: ENT_HTML401, ENT_HTML5, ENT_XML1 and ENT_XHTML. In PHP 5.0, add support for multi-byte encodings. |
More examples
Example 1
Some HTML into character entities:
$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
?>
HTML output of the code above is as follows (view source):
<html>
<body>
Jane & 'Tarzan'<br>
Jane & 'Tarzan'<br>
Jane & 'Tarzan'
</body>
</html>
Browser output of the code above is as follows:
Jane & 'Tarzan'
Jane & 'Tarzan'
Example 2
By using the Western European character sets, some HTML into character entities:
$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>
Browser output of the code above is as follows:
PHP String Reference