Symfony\Polyfill\Mbstring

Mbstring::mb_ord │ public static │ CF7 1.0

Метод класса: Mbstring{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

$result = Mbstring::mb_ord( $s, $encoding );
$s(обязательный)
.
$encoding
.
По умолчанию: null

Код Mbstring::mb_ord() CF7 6.2.4.1

public static function mb_ord($s, $encoding = null)
{
    if ('' === (string) $s) {
        if (80000 > \PHP_VERSION_ID) {
            trigger_error('mb_ord(): Empty string', \E_USER_WARNING);

            return false;
        }

        throw new \ValueError('mb_ord(): Argument #1 ($string) must not be empty');
    }

    if (null !== $encoding && !self::assertCodepointEncoding($encoding, 'mb_ord')) {
        return false;
    }

    if ('UTF-8' !== $encoding = self::getEncoding($encoding)) {
        $s = mb_convert_encoding($s, 'UTF-8', $encoding);
    }

    $s = unpack('C*', substr($s, 0, 4));
    $code = $s[1] ?? 0;
    if (0x80 > $code) {
        return $code;
    }

    if (0xC2 > $code || 0xF4 < $code) {
        return false;
    }

    $c2 = $s[2] ?? 0;
    if (0x80 !== ($c2 & 0xC0)) {
        return false;
    }

    if (0xE0 > $code) {
        return (($code & 0x1F) << 6) | ($c2 & 0x3F);
    }

    $c3 = $s[3] ?? 0;
    if (0x80 !== ($c3 & 0xC0)
        || 0xE0 === $code && 0xA0 > $c2
        || 0xED === $code && 0xA0 <= $c2
    ) {
        return false;
    }

    if (0xF0 > $code) {
        return (($code & 0x0F) << 12) | (($c2 & 0x3F) << 6) | ($c3 & 0x3F);
    }

    $c4 = $s[4] ?? 0;
    if (0x80 !== ($c4 & 0xC0)
        || 0xF0 === $code && 0x90 > $c2
        || 0xF4 === $code && 0x90 <= $c2
    ) {
        return false;
    }

    return (($code & 0x07) << 18) | (($c2 & 0x3F) << 12) | (($c3 & 0x3F) << 6) | ($c4 & 0x3F);
}