IntlChar::charName() function in PHP

PHPServer Side ProgrammingProgramming

The IntlChar::charName()function gets the name of a Unicode character.

Syntax

string IntlChar::charName( val [, choice = IntlChar::UNICODE_CHAR_NAME] )

Parameters

  • val − An integer value or character encoded as UTF-8 string.

  • choice − The following are the constant conditions −

    • IntlChar::UNICODE_CHAR_NAME

    • IntlChar::CHAR_NAME_ALIAS

    • IntlChar::CHAR_NAME_CHOICE_COUNT

    • IntlChar::UNICODE_10_CHAR_NAME

    • IntlChar::EXTENDED_CHAR_NAME

Return

The IntlChar::charName() function returns the corresponding name of input data. For no name of character, an empty string is returned.

Example

The following is an example −

<?php
   var_dump(IntlChar::charName("&"));
   echo "<br>";
   var_dump(IntlChar::charName("&", IntlChar::EXTENDED_CHAR_NAME));
?>

Output

The following is the output −

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

Example

Let us see another example −

<?php
   var_dump(IntlChar::charName("K"));
   echo "<br>";
   var_dump(IntlChar::charName("K", IntlChar::EXTENDED_CHAR_NAME));
?>

Output

The following is the output −

string(22) "LATIN CAPITAL LETTER K"
string(22) "LATIN CAPITAL LETTER K"

Example

Let us see one more example with a different input value −

<?php
   var_dump(IntlChar::charName("5"));
   echo "<br>";
   var_dump(IntlChar::charName("10"));  
   echo "<br>";
   var_dump(IntlChar::charName("e"));
   echo "<br>";
   var_dump(IntlChar::charName("}"));
?>

Output

The following is the output −

string(10) "DIGIT FIVE"
NULL
string(20) "LATIN SMALL LETTER E"
string(19) "RIGHT CURLY BRACKET"
raja
Updated on 30-Dec-2019 08:08:13

Advertisements