PHP 8 reference · String Functions
PHP html_entity_decode() Function
Convert HTML entities such as &, < and é back into the characters they stand for.
PHP 8 Since 4.3
Syntax
html_entity_decode(string $string, int $flags = ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401, ?string $encoding = null): string
Parameters
| Parameter | Description |
|---|---|
string |
The input string. |
flags optional |
Which quotes and document type to handle. Default: ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 |
encoding optional |
The character encoding; defaults to UTF-8. |
Return value
The decoded string.
Examples
<?php
echo html_entity_decode("Fish & Chips – £9"), "\n";
Output
Fish & Chips – £9
<?php
echo html_entity_decode("It's <b>bold</b>"), "\n";
Output
It's <b>bold</b>
Version history
| Version | Change |
|---|---|
| PHP 4.3 | Added |
| PHP 8.1 | The default flags became ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401, so ' is decoded by default. |
Related
htmlspecialchars()· Convert &, <, >, " and ' to HTML entities so user text is shown as text, not run as HTML. The main defence against XSS.strip_tags()· Remove HTML and PHP tags from a string, keeping the text. You can allow some tags, but it's no XSS protection.- PHP Strings · tutorial