PHP | IntlChar::charName() Function

The IntlChar::charName() function is an inbuilt function in PHP used to retrieve the name of a Unicode character.

Syntax:

string IntlChar::charName( $codepoint [, $nameChoice = IntlChar::UNICODE_CHAR_NAME] )

Parameters: This function accepts two parameters as mentioned above and described below:

  • $codepoint: This parameter is a character or integer value, which is encoded as a UTF-8 string.
  • $nameChoice: The $nameChoice parameter is satisfied one of any following constant condition:
    • IntlChar::UNICODE_CHAR_NAME (default)
    • IntlChar::CHAR_NAME_ALIAS
    • IntlChar::CHAR_NAME_CHOICE_COUNT
    • IntlChar::UNICODE_10_CHAR_NAME
    • IntlChar::EXTENDED_CHAR_NAME

Note: The resulting character name is modern name with Unicode version 1.0 and the name contains “invariant” characters A-Z, 0-9, ” “, and ‘-‘ and depends its $nameChoice parameter.

Return Value: This function returns the corresponding name of input data. If there is no name of character then return the empty string.

Below programs illustrate the IntlChar::charName() Function in PHP.
Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
// PHP code to illustrate
// IntlChar::charName ()function
   
// Input astrick symbol of codepoint  value 
// with constraint UNICODE_CHAR_NAME 
var_dump(IntlChar::charName("*"));
echo "<br>";
var_dump(IntlChar::charName("*", IntlChar::UNICODE_CHAR_NAME));
echo "<br> <br>";
   
// Input start bracket symbol of codepoint  value 
// with constraint UNICODE_10_CHAR_NAME 
var_dump(IntlChar::charName("("));
echo "<br>";
var_dump(IntlChar::charName("(", IntlChar::UNICODE_10_CHAR_NAME));
echo "<br> <br>";
   
// Input ampersand symbol of codepoint value 
// with constraint EXTENDED_CHAR_NAME
var_dump(IntlChar::charName("&"));
echo "<br>";
var_dump(IntlChar::charName("&", IntlChar::EXTENDED_CHAR_NAME));
echo "<br> <br>";
   
// Input ^ symbol of codepoint value 
// with constraint CHAR_NAME_ALIAS
var_dump(IntlChar::charName("^"));
echo "<br>";
var_dump(IntlChar::charName("^", IntlChar::CHAR_NAME_ALIAS ));
echo "<br> <br>";
   
// Input tile symbol of codepoint value 
//and  with constraint CHAR_NAME_CHOICE_COUNT
var_dump(IntlChar::charName("`"));
echo "<br>";
var_dump(IntlChar::charName("`", IntlChar::CHAR_NAME_CHOICE_COUNT));
echo "<br> <br>";
   
// Input space of codepoint value
var_dump(IntlChar::charName(" "));
echo "<br>";
  
// Input space in codepoint value with 
// UNICODE_CHAR_NAME condition
var_dump(IntlChar::charName(" ", IntlChar::UNICODE_CHAR_NAME));
echo "<br> <br>";
   
// Input Alphabet both Capital and Small character
// condition EXTENDED_CHAR_NAME
// and UNICODE_10_CHAR_NAME
var_dump(IntlChar::charName("R"));
echo "<br>";
var_dump(IntlChar::charName("r"));
echo "<br>";
var_dump(IntlChar::charName("R", IntlChar::EXTENDED_CHAR_NAME));
echo "<br> <br>";
   
// Input int codepoint value
var_dump(IntlChar::charName("10"));
echo "<br>";
var_dump(IntlChar::charName("7"));
echo "<br> <br>";
   
// Input Null codepoint value
var_dump(IntlChar::charName("\u{0000}"));
echo "<br>";
   
?>

chevron_right


Output:

string(8) "ASTERISK" 
string(8) "ASTERISK" 

string(16) "LEFT PARENTHESIS" 
string(0) "" 

string(9) "AMPERSAND" 
string(9) "AMPERSAND" 

string(17) "CIRCUMFLEX ACCENT" 
string(0) "" 

string(12) "GRAVE ACCENT" 
NULL 

string(5) "SPACE" 
string(5) "SPACE" 

string(22) "LATIN CAPITAL LETTER R" 
string(20) "LATIN SMALL LETTER R" 
string(22) "LATIN CAPITAL LETTER R" 

NULL 
string(11) "DIGIT SEVEN" 

string(0) "" 

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// PHP code to illustrate
// IntlChar::charName() function
  
// Declare an array $arr
$arr = array("G", ".", "8", "/", "000", "\t");
  
// Loop run for every array element
foreach ($arr as $val){
      
    // Check each element as code point data
    var_dump(IntlChar::charName($val));
    echo "<br>";
}
?>

chevron_right


Output:

string(22) "LATIN CAPITAL LETTER G" 
string(9) "FULL STOP" 
string(11) "DIGIT EIGHT" 
string(7) "SOLIDUS" 
NULL 
string(0) "" 

Related Articles:

Reference: http://php.net/manual/en/intlchar.charname.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 :

Be the First to upvote.


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