4.6.x common.inc decode_entities($text, $exclude = array())
4.7.x unicode.inc decode_entities($text, $exclude = array())
5.x unicode.inc decode_entities($text, $exclude = array())
6.x unicode.inc decode_entities($text, $exclude = array())
7.x unicode.inc decode_entities($text)

Decode all HTML entities (including numerical ones) to regular UTF-8 bytes. Double-escaped entities will only be decoded once ("&amp;lt;" becomes "&lt;", not "<").


$text: The text to decode entities in.

$exclude: An array of characters which should not be decoded. For example, array('<', '&', '"'). This affects both named and numerical entities.

Related topics

4 calls to decode_entities()
aggregator_parse_feed in modules/aggregator.module
comment_validate_form in modules/comment.module
filter_xss_bad_protocol in modules/filter.module
Processes an HTML attribute value and ensures it does not contain an URL with a disallowed protocol (e.g. javascript:)
search_keywords_split in modules/search.module
Splits a string into component words according to indexing rules.


includes/common.inc, line 1784
Common functions that many Drupal modules will need to reference.


function decode_entities($text, $exclude = array()) {
  static $table;

  // We store named entities in a table for quick processing.
  if (!isset($table)) {

    // Get all named HTML entities.
    $table = array_flip(get_html_translation_table(HTML_ENTITIES));

    // PHP gives us ISO-8859-1 data, we need UTF-8.
    $table = array_map('utf8_encode', $table);

    // Add apostrophe (XML)
    $table['&apos;'] = "'";
  $newtable = array_diff($table, $exclude);

  // Use a regexp to select all entities in one pass, to avoid decoding double-escaped entities twice.
  return preg_replace('/&(#x?)?([A-Za-z0-9]+);/e', '_decode_entities("$1", "$2", "$0", $newtable, $exclude)', $text);