mb_chr
(PHP 7 >= 7.2.0, PHP 8)
mb_chr — Return character by Unicode code point value
說明
mb_chr(int
$codepoint
, ?string $encoding
= null
): string|falseReturns a string containing the character specified by the Unicode code point value, encoded in the specified encoding.
This function complements mb_ord().
參數
-
codepoint
-
A Unicode codepoint value, e.g.
128024
for U+1F418 ELEPHANT -
encoding
-
encoding
參數為字元編碼。如果省略或是null
,則使用內部字元編碼。
返回值
A string containing the requested character, if it can be represented in the specified
encoding 或者在失敗時返回 false
.
更新日誌
版本 | 說明 |
---|---|
8.0.0 |
現在 encoding 可以為 null。
|
範例
示例 #1 Testing different code points
<?php
$values = [65, 63, 0x20AC, 128024];
foreach ($values as $value) {
var_dump(mb_chr($value, 'UTF-8'));
var_dump(mb_chr($value, 'ISO-8859-1'));
}
?>
以上例程會輸出:
string(1) "A" string(1) "A" string(1) "?" string(1) "?" string(3) "€" bool(false) string(4) "🐘" bool(false)
參見
- mb_internal_encoding() - 設定/獲取內部字元編碼
- mb_ord() - Get Unicode code point of character
- IntlChar::ord() - Return Unicode code point value of character
- chr() - 返回指定的字元