W3cubDocs

/Drupal 8

public static function Html::decodeEntities

public static Html::decodeEntities($text)

Decodes all HTML entities including numerical ones to regular UTF-8 bytes.

Double-escaped entities will only be decoded once ("&amp;lt;" becomes "&lt;", not "<"). Be careful when using this function, as it will revert previous sanitization efforts (&lt;script&gt; will become <script>).

This method is not the opposite of Html::escape(). For example, this method will convert "&eacute;" to "é", whereas Html::escape() will not convert "é" to "&eacute;".

Parameters

string $text: The text to decode entities in.

Return value

string The input $text, with all HTML entities decoded once.

See also

html_entity_decode()

\Drupal\Component\Utility\Html::escape()

File

core/lib/Drupal/Component/Utility/Html.php, line 363

Class

Html
Provides DOMDocument helpers for parsing and serializing HTML strings.

Namespace

Drupal\Component\Utility

Code

public static function decodeEntities($text) {
  return html_entity_decode($text, ENT_QUOTES, 'UTF-8');
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Component!Utility!Html.php/function/Html::decodeEntities/8.1.x