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

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

html_entity_decode(string $string, int $flags = ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401, ?string $encoding = null): string

Parameters

ParameterDescription
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

Decode named entitiesTry it yourself
<?php
echo html_entity_decode("Fish &amp; Chips &ndash; &pound;9"), "\n";

Output

Fish & Chips – £9
Numeric entities and tagsTry it yourself
<?php
echo html_entity_decode("It&#039;s &lt;b&gt;bold&lt;/b&gt;"), "\n";

Output

It's <b>bold</b>

Version history

VersionChange
PHP 4.3Added
PHP 8.1The default flags became ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401, so &#039; is decoded by default.

Was this page helpful?