Tutorialspoint.dev

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



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

Output:

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

Program 2:

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

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



This article is attributed to GeeksforGeeks.org

You Might Also Like

leave a comment

code

0 Comments

load comments

Subscribe to Our Newsletter