PHP | IntlChar::chr() Function

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 interger 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:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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("@"));
  
?>

chevron_right


Output:

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

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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));
}
?>

chevron_right


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



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.