function Html::decodeEntities

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Component/Utility/Html.php \Drupal\Component\Utility\Html::decodeEntities()
  2. 8.9.x core/lib/Drupal/Component/Utility/Html.php \Drupal\Component\Utility\Html::decodeEntities()
  3. 11.x core/lib/Drupal/Component/Utility/Html.php \Drupal\Component\Utility\Html::decodeEntities()

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()

12 calls to Html::decodeEntities()
EntityAutocompleteMatcher::getMatches in core/lib/Drupal/Core/Entity/EntityAutocompleteMatcher.php
Gets matched labels based on a given search string.
FormBuilder::buttonWasClicked in core/lib/Drupal/Core/Form/FormBuilder.php
Determines if a given button triggered the form submission.
HtmlTest::testDecodeEntities in core/tests/Drupal/Tests/Component/Utility/HtmlTest.php
Tests Html::decodeEntities().
HtmlTest::testDecodeEntitiesAndEscape in core/tests/Drupal/Tests/Component/Utility/HtmlTest.php
Tests relationship between escaping and decoding HTML entities.
HtmlTest::testDeprecations in core/tests/Drupal/Tests/Component/Utility/HtmlTest.php
Test deprecations.

... See full list

File

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

Class

Html
Provides DOMDocument helpers for parsing and serializing HTML strings.

Namespace

Drupal\Component\Utility

Code

public static function decodeEntities($text) : string {
  if (is_null($text)) {
    @trigger_error('Passing NULL to ' . __METHOD__ . ' is deprecated in drupal:9.5.0 and will trigger a PHP error from drupal:11.0.0. Pass a string instead. See https://www.drupal.org/node/3318826', E_USER_DEPRECATED);
    return '';
  }
  return html_entity_decode($text, ENT_QUOTES, 'UTF-8');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.