Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Mbstring.php

function Mbstring::mb_decode_numericentity

File

vendor/symfony/polyfill-mbstring/Mbstring.php, line 155

Class

Mbstring
Partial mbstring implementation in PHP, iconv based, UTF-8 centric.

Namespace

Symfony\Polyfill\Mbstring

Code

public static function mb_decode_numericentity($s, $convmap, $encoding = null) {
    if (null !== $s && !\is_scalar($s) && !(\is_object($s) && method_exists($s, '__toString'))) {
        trigger_error('mb_decode_numericentity() expects parameter 1 to be string, ' . \gettype($s) . ' given', \E_USER_WARNING);
        return null;
    }
    if (!\is_array($convmap) || 80000 > \PHP_VERSION_ID && !$convmap) {
        return false;
    }
    if (null !== $encoding && !\is_scalar($encoding)) {
        trigger_error('mb_decode_numericentity() expects parameter 3 to be string, ' . \gettype($s) . ' given', \E_USER_WARNING);
        return '';
        // Instead of null (cf. mb_encode_numericentity).
    }
    $s = (string) $s;
    if ('' === $s) {
        return '';
    }
    $encoding = self::getEncoding($encoding);
    if ('UTF-8' === $encoding) {
        $encoding = null;
        if (!preg_match('//u', $s)) {
            $s = @iconv('UTF-8', 'UTF-8//IGNORE', $s);
        }
    }
    else {
        $s = iconv($encoding, 'UTF-8//IGNORE', $s);
    }
    $cnt = floor(\count($convmap) / 4) * 4;
    for ($i = 0; $i < $cnt; $i += 4) {
        // collector_decode_htmlnumericentity ignores $convmap[$i + 3]
        $convmap[$i] += $convmap[$i + 2];
        $convmap[$i + 1] += $convmap[$i + 2];
    }
    $s = preg_replace_callback('/&#(?:0*([0-9]+)|x0*([0-9a-fA-F]+))(?!&);?/', function (array $m) use ($cnt, $convmap) {
        $c = isset($m[2]) ? (int) hexdec($m[2]) : $m[1];
        for ($i = 0; $i < $cnt; $i += 4) {
            if ($c >= $convmap[$i] && $c <= $convmap[$i + 1]) {
                return self::mb_chr($c - $convmap[$i + 2]);
            }
        }
        return $m[0];
    }, $s);
    if (null === $encoding) {
        return $s;
    }
    return iconv('UTF-8', $encoding . '//IGNORE', $s);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal