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 ("&lt;" becomes "<", 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.
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 