mb_ord
(PHP 7 >= 7.2.0, PHP 8)
mb_ord — Get Unicode code point of character
說明
mb_ord(string
$string
, ?string $encoding
= null
): int|falseReturns the Unicode code point value of the given character.
This function complements mb_chr().
參數
-
string
-
A string
-
encoding
-
encoding
參數為字元編碼。如果省略或是null
,則使用內部字元編碼。
返回值
The Unicode code point for the first character of string
或者在失敗時返回 false
.
更新日誌
版本 | 說明 |
---|---|
8.0.0 |
現在 encoding 可以為 null。
|
範例
<?php
var_dump(mb_ord("A", "UTF-8"));
var_dump(mb_ord("🐘", "UTF-8"));
var_dump(mb_ord("\x80", "ISO-8859-1"));
var_dump(mb_ord("\x80", "Windows-1252"));
?>
以上例程會輸出:
int(65)
int(128024)
int(128)
int(8364)
參見
- mb_internal_encoding() - 設定/獲取內部字元編碼
- mb_chr() - Return character by Unicode code point value
- IntlChar::ord() - Return Unicode code point value of character
- ord() - 轉換字串第一個位元組為 0-255 之間的值