Open In App

PHP mb_chr() Function

The mb_chr() function is an inbuilt function in PHP that is used to return the character unicode point value that is encoded into the specified encoding.

Syntax: 



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

Parameters: This function accepts two parameters that are described below:

Return Value: This parameter returns a string that contains the requested character. It returns the specified encoding or false on failure.



Example 1: The following code demonstrates the PHP mb_chr() method.




<?php
  
// Create an array with the character
// unicode values
$char_code = [71, 101, 101, 107, 115];
  
// Return the character for each
// unicode array values
foreach ($char_code as $index) {
    print_r(mb_chr($index, 'ASCII'));
}
  
?>

Output
Geeks

Example 2: The following code is another example of the PHP mb_chr() method.




<?php
  
// Create an array with character
// unicode values
$char_code = [0x71, 0x101, 0x104, 0x107, 0x115];
  
// Return the character for each
// unicode array values
foreach ($char_code as $index) {
    print_r(mb_chr($index, 'UTF-8'));
}
  
?>

Output
qāĄćĕ

Reference: https://www.php.net/manual/en/function.mb-chr.php

Article Tags :