
- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
PHP â How to return character by Unicode code point value using mb_chr()?
In PHP, the mb_chr() function is used to return character by Unicode code point value. This function returns a string having the character identified by the Unicode code point value, encoded in the specified encoding.
Syntax
string mb_chr(int $codepoint, string $encoding)
Parameters
mb_chr() accepts only two parameters: $codepoint and $encoding.
$codepoint− This parameter is used to convert a Unicode codepoint value. For example, 128024 for U+1F418 ELEPHANT.
$encoding− This parameter is the character encoding. If it is absent or null, then the internal character encoding value will be used.
Return Values
This function returns a string containing the requested character if it can be represented in the specified encoding or it returns False on failure.
Note: From PHP 8.0, nullable encoding is allowed.
Example
<pre> <?php $str = [66, 64, 0x20AC, 128024]; foreach ($str as $str) { var_dump(mb_chr($str, 'UTF-8')); var_dump(mb_chr($str, 'ISO-8859-1')); } ?> </pre>
Output
string(1) "B" string(1) "B" string(1) "@" string(1) "@" string(3) "€" bool(false) string(4) "ð" bool(false)
Note: PHP IntlChar::chr() function can be used to convert from PHP Unicode codepoint to character.
- Related Articles
- PHP â How to get the Unicode point value of a given character?
- How to return a number indicating the Unicode value of the character?
- PHP â How to return the character count of a string using iconv_strlen()?
- chr() function in PHP
- Java Program to Determine the Unicode Code Point at a given index
- IntlChar::chr() function in PHP
- How to print Unicode character in C++?
- How to fetch character from Unicode number - JavaScript?
- Match Unicode character specified by the hexadecimal number XXXX.
- PHP â How to detect character encoding using mb_detect_encoding()
- PHP â How to get the substitution character using mb_substitute_character()?
- PHP Return by Reference
- How to convert an integer to a unicode character in Python?
- Convert the value of the specified string to its equivalent Unicode character in C#
- Query MySQL with unicode char code?
