_mb_ord()
Internal compat function to mimic mb_ord().
Внутренняя функция — эта функция рассчитана на использование самим ядром. Не рекомендуется использовать эту функцию в своем коде.
Хуков нет.
Возвращает
int|false. The Unicode code point for the first character of string or false on failure.
Использование
_mb_ord( $string, $encoding );
- $string(строка) (обязательный)
- Return the code point at the start of this string.
- $encoding("UTF-8"|null)
- Must be
'UTF-8'or null.
По умолчанию:null
Список изменений
| С версии 7.1.0 | Введена. |
Код _mb_ord() mb ord WP 7.1.4
function _mb_ord( $string, $encoding = null ) {
if ( ! is_string( $string ) || '' === $string || ( isset( $encoding ) && 'UTF-8' !== $encoding ) ) {
return false;
}
$byte_length = 0;
$invalid_length = 0;
$found_count = _wp_scan_utf8( $string, $byte_length, $invalid_length, null, 1 );
if ( 1 !== $found_count ) {
return false;
}
// These are valid code points, so no further validation is required.
$b0 = ord( $string[0] );
switch ( $byte_length ) {
case 1:
return $b0;
case 2:
return (
( ( $b0 & 0x1F ) << 6 ) |
( ( ord( $string[1] ) & 0x3F ) )
);
case 3:
return (
( ( $b0 & 0x0F ) << 12 ) |
( ( ord( $string[1] ) & 0x3F ) << 6 ) |
( ( ord( $string[2] ) & 0x3F ) )
);
case 4:
return (
( ( $b0 & 0x07 ) << 18 ) |
( ( ord( $string[1] ) & 0x3F ) << 12 ) |
( ( ord( $string[2] ) & 0x3F ) << 6 ) |
( ( ord( $string[3] ) & 0x3F ) )
);
}
return false;
}