decode_entities

Versions
4.6 – 7
decode_entities($text, $exclude = array())

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 "<").

Parameters

$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.

▾ 8 functions call decode_entities()

comment_submit in modules/comment/comment.module
Prepare a comment for submission.
drupal_html_to_text in includes/mail.inc
Transform an HTML string into plain text, preserving the structure of the markup. Useful for preparing the body of a node to be sent by e-mail.
filter_xss_bad_protocol in includes/common.inc
Processes an HTML attribute value and ensures it does not contain an URL with a disallowed protocol (e.g. javascript:).
format_rss_channel in includes/common.inc
Formats an RSS channel.
locale_string_is_safe in includes/locale.inc
Check that a string is safe to be added or imported as a translation.
search_simplify in modules/search/search.module
Simplifies a string according to indexing rules.
_filter_url_parse_full_links in modules/filter/filter.module
Make links out of absolute URLs.
_filter_url_parse_partial_links in modules/filter/filter.module
Make links out of domain names starting with "www."

Code

includes/unicode.inc, line 328

<?php
function decode_entities($text, $exclude = array()) {
  static $html_entities;
  if (!isset($html_entities)) {
    include DRUPAL_ROOT . '/includes/unicode.entities.inc';
  }

  // Flip the exclude list so that we can do quick lookups later.
  $exclude = array_flip($exclude);

  // Use a regexp to select all entities in one pass, to avoid decoding
  // double-escaped entities twice. The PREG_REPLACE_EVAL modifier 'e' is
  // being used to allow for a callback (see
  // http://php.net/manual/en/reference.pcre.pattern.modifiers).
  return preg_replace('/&(#x?)?([A-Za-z0-9]+);/e', '_decode_entities("$1", "$2", "$0", $html_entities, $exclude)', $text);
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.