PHP.nl

html_entity_decode

html_entity_decode

Convert HTML entities to their corresponding characters

string **html_entity_decode** string $string int $flags  $encoding
is the opposite of
in that it converts HTML entities

in the to their corresponding characters. html_entity_decode``htmlentities``string

More precisely, this function decodes all the entities (including all numeric entities) that a) are necessarily valid for the chosen document type — i.e., for XML, this function does not decode named entities that might be defined in some DTD — and b) whose character or characters are in the coded character set associated with the chosen encoding and are permitted in the chosen document type. All other entities are left as is.

stringThe input string.

flags A bitmask of one or more of the following flags, which specify how to handle quotes and which document type to use. The default is .

  `ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401`

encoding

Returns the decoded string.

Voorbeeld: Decoding HTML entities

<?php
$orig = "I'll \"walk\" the <b>dog</b> now";

$a = htmlentities($orig);

$b = html_entity_decode($a);

echo $a, PHP_EOL; // I'll &quot;walk&quot; the &lt;b&gt;dog&lt;/b&gt; now

echo $b, PHP_EOL; // I'll "walk" the <b>dog</b> now
?>

Opmerking: > You might wonder why trim(html_entity_decode(' ')); doesn't reduce the string to an empty string, that's because the ' ' entity is not ASCII code 32 (which is stripped by ) but ASCII code 160 (0xa0) in the default ISO 8859-1 encoding. trim

htmlentities``htmlspecialchars``get_html_translation_table``urldecode