function _decode_entities in Drupal 5
Same name and namespace in other branches
- 4 includes/unicode.inc \_decode_entities()
- 6 includes/unicode.inc \_decode_entities()
Helper function for decode_entities
File
- includes/
unicode.inc, line 316
Code
function _decode_entities($prefix, $codepoint, $original, &$table, &$exclude) {
// Named entity
if (!$prefix) {
if (isset($table[$original])) {
return $table[$original];
}
else {
return $original;
}
}
// Hexadecimal numerical entity
if ($prefix == '#x') {
$codepoint = base_convert($codepoint, 16, 10);
}
else {
$codepoint = preg_replace('/^0+/', '', $codepoint);
}
// Encode codepoint as UTF-8 bytes
if ($codepoint < 0x80) {
$str = chr($codepoint);
}
else {
if ($codepoint < 0x800) {
$str = chr(0xc0 | $codepoint >> 6) . chr(0x80 | $codepoint & 0x3f);
}
else {
if ($codepoint < 0x10000) {
$str = chr(0xe0 | $codepoint >> 12) . chr(0x80 | $codepoint >> 6 & 0x3f) . chr(0x80 | $codepoint & 0x3f);
}
else {
if ($codepoint < 0x200000) {
$str = chr(0xf0 | $codepoint >> 18) . chr(0x80 | $codepoint >> 12 & 0x3f) . chr(0x80 | $codepoint >> 6 & 0x3f) . chr(0x80 | $codepoint & 0x3f);
}
}
}
}
// Check for excluded characters
if (in_array($str, $exclude)) {
return $original;
}
else {
return $str;
}
}