Open In App

PHP | IntlChar::chr() Function

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Share
Report issue
Report

The IntlChar::chr() function is an inbuilt function in PHP which is used to check whether the given input character is Unicode code point value or not. It returns Unicode character by code point value.
Syntax: 
 

string IntlChar::chr( $codepoint )

Parameters: This function accepts a single parameter $codepoint which is mandatory. The input parameter is a character or integer value, which is encoded as a UTF-8 string.
Return Value: In True cases, the $codepoint string contain the single character, which is specified by the Unicode code point value, otherwise return NULL.
Below programs illustrate the IntlChar::chr() function in PHP: 
Program 1: 
 

php




<?php
// PHP function to illustrate
// the use of IntlChar::chr()
    
// Input int codepoint value
var_dump(IntlChar::chr(" "));
    
// Input int codepoint value
var_dump(IntlChar::chr(101));
    
// Input char codepoint value
var_dump(IntlChar::chr("G"));
    
// Input char  codepoint value
var_dump(IntlChar::chr("Geeks"));
 
// Input Symbolic codepoint value
var_dump(IntlChar::chr("$"));
 
// Input Symbolic codepoint value
var_dump(IntlChar::chr("#"));
  
// Input Symbolic codepoint value
var_dump(IntlChar::chr("@"));
 
?>


Output: 
 

string(1) " " 
string(1) "e" 
string(1) "G" 
NULL 
string(1) "$" 
string(1) "#" 
string(1) "@" 

Program 2: 
 

php




<?php
// PHP function to illustrate the
// use of IntlChar::chr
 
// Declare an array with
// different codepoint value
$arr = array("D",
            ("E"),
             77,
            123,
            65,
            97,
      
        );
      
// For loop condition to check
// each character through function
foreach ($arr as $val) {
          
    // Check each element as code point data
    var_dump(IntlChar::chr($val));
}
?>


Output: 
 

string(1) "D" 
string(1) "E" 
string(1) "M"  
string(1) "{" 
string(1) "A" 
string(1) "a" 

Related Articles: 
 

Reference: http://php.net/manual/en/intlchar.chr.php
 



Last Updated : 25 Mar, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads