mb_chr

(PHP 7 >= 7.2.0, PHP 8)

mb_chrReturn character by Unicode code point value

说明

mb_chr ( int $codepoint , string|null $encoding = null ) : string|false

Returns 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.

范例

示例 #1 Testing different code points

<?php
$values 
= [65630x20AC128024];
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)

更新日志

版本 说明
8.0.0 现在 encoding 可以为 null。

参见