How to Use the PHP Function mb_chr()
In PHP there are a lot of functions that accept many different arguments. Some are widely used, others are less so. One such function is the mb_chr(), which returns a character based on its Unicode code point value, encoded into the specified encoding.
This article will show you how to use it.
mb_chr() is an inbuilt function in PHP which can be used to return character based on its Unicode code point. It takes two parameters; $codepoint, which holds the Unicode code point value and $encoding which describes character encoding. If the parameter value is omitted or null, the internal character encoding value will be used.
The function uses the well-known mbstring extension to do its job. If the mbstring extension is not loaded, it will fall back to iconv, which is also widely used.
This function complements mb_ord() by providing the ability to return a single-character string based on a code point value instead of interpreting it as an integer. The mb_chr() function will not know about multiple-byte encodings, and it cannot convert from a character code point value to an equivalent sequence in any such encoding.
Unlike strtolower() and strtoupper(), which are based on locale settings, the mb_chr() function does not use locale settings. This allows the function to work correctly in a wide range of languages and browsers, including some with strict UTF-8 encodings. The only exception is that high Unicode characters outside the Basic Multilingual Plane, or characters composed of four or more bytes (hieroglyhps and cuneiform) will pass through.