_mb_chr()
Internal compat function to mimic mb_chr().
Внутренняя функция — эта функция рассчитана на использование самим ядром. Не рекомендуется использовать эту функцию в своем коде.
Хуков нет.
Возвращает
string|false. A string containing the requested character, if it can be represented in the specified encoding or false on failure.
Использование
_mb_chr( $codepoint, $encoding );
- $codepoint(int) (обязательный)
- A Unicode codepoint value, e.g. 128024 for U+1F418 ELEPHANT.
- $encoding("UTF-8"|null)
- Must be
'UTF-8'or null.
По умолчанию:null
Список изменений
| С версии 7.1.0 | Введена. |
Код _mb_chr() mb chr WP 7.1.4
function _mb_chr( $codepoint, $encoding = null ) {
if ( ! is_int( $codepoint ) || ( isset( $encoding ) && 'UTF-8' !== $encoding ) ) {
return false;
}
// Pre-check to ensure a valid code point.
if (
$codepoint < 0 ||
( $codepoint >= 0xD800 && $codepoint <= 0xDFFF ) ||
$codepoint > 0x10FFFF
) {
return false;
}
if ( $codepoint <= 0x7F ) {
return chr( $codepoint );
}
if ( $codepoint <= 0x7FF ) {
$byte1 = chr( ( $codepoint >> 6 ) | 0xC0 );
$byte2 = chr( $codepoint & 0x3F | 0x80 );
return "{$byte1}{$byte2}";
}
if ( $codepoint <= 0xFFFF ) {
$byte1 = chr( ( $codepoint >> 12 ) | 0xE0 );
$byte2 = chr( ( $codepoint >> 6 ) & 0x3F | 0x80 );
$byte3 = chr( $codepoint & 0x3F | 0x80 );
return "{$byte1}{$byte2}{$byte3}";
}
// Any values above U+10FFFF are eliminated above in the pre-check.
$byte1 = chr( ( $codepoint >> 18 ) | 0xF0 );
$byte2 = chr( ( $codepoint >> 12 ) & 0x3F | 0x80 );
$byte3 = chr( ( $codepoint >> 6 ) & 0x3F | 0x80 );
$byte4 = chr( $codepoint & 0x3F | 0x80 );
return "{$byte1}{$byte2}{$byte3}{$byte4}";
}