mb_chr()
mb_chr() — Return character by Unicode code point value.
Built-in function of PHP 8.5. The manual lists it as available in PHP 7 >= 7.2.0, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
Returns a string containing the character specified by the Unicode code point value, encoded in the specified encoding.
Signature
mb_chr(int $codepoint, ?string $encoding = null): string|false
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $codepoint | int | A Unicode codepoint value, e.g. 128024 for U+1F418 ELEPHANT |
| $encoding | ?string | The encoding parameter is the character encoding. If it is omitted or null, the internal character encoding value will be used. |
Return value
A string containing the requested character, if it can be represented in the specified encoding or false on failure.
Example
A runnable snippet:
$values = [65, 63, 0x20AC, 128024]; foreach ($values as $value) { var_dump(mb_chr($value, 'UTF-8')); var_dump(mb_chr($value, 'ISO-8859-1')); }
Output:
string(1) "A" string(1) "A" string(1) "?" string(1) "?" string(3) "€" bool(false) string(4) "🐘" bool(false)
Changelog
| Version | Change |
|---|---|
| 8.0.0 | encoding is nullable now. |
| 8.0.0 | Now throws a ValueError if encoding is an invalid encoding. Previously, an E_WARNING was emitted and false was returned. |
See also
mb_internal_encoding(), mb_ord(), chr()
All PHP 8.5 built-in functions
Reference card built from the PHP manual page mb_chr() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.