Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
IntlChar::charName() function in PHP
The IntlChar::charName() function gets the name of a Unicode character. This is useful for identifying characters by their official Unicode names.
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 Value
The IntlChar::charName() function returns the corresponding name of input data. For no name of character, an empty string is returned.
Example 1
The following example shows character name retrieval ?
<?php
var_dump(IntlChar::charName("&"));
echo "<br>";
var_dump(IntlChar::charName("&", IntlChar::EXTENDED_CHAR_NAME));
?>
string(9) "AMPERSAND" string(9) "AMPERSAND"
Example 2
Let us see another example with letter characters ?
<?php
var_dump(IntlChar::charName("K"));
echo "<br>";
var_dump(IntlChar::charName("K", IntlChar::EXTENDED_CHAR_NAME));
?>
string(22) "LATIN CAPITAL LETTER K" string(22) "LATIN CAPITAL LETTER K"
Example 3
Let us see one more example with different input values ?
<?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("}"));
?>
string(10) "DIGIT FIVE" NULL string(20) "LATIN SMALL LETTER E" string(19) "RIGHT CURLY BRACKET"
Conclusion
The IntlChar::charName() function provides an easy way to retrieve Unicode character names. It returns NULL for invalid characters and empty strings for characters without names.
