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::charAge() function in PHP
The IntlChar::charAge() function is used to compute the age of a Unicode character, which represents the Unicode version when the character was first designated or assigned.
Syntax
array IntlChar::charAge( mixed $codepoint )
Parameters
codepoint − A character or integer value encoded as a UTF-8 string, or an integer representing the Unicode code point.
Return Value
The IntlChar::charAge() function returns an array containing the Unicode version number as four integers representing [major, minor, micro, update]. Returns null on failure.
Example
The following example demonstrates how to get the Unicode age of different characters −
<?php
// Check age of Latin letter 'A' (very old character)
var_dump(IntlChar::charAge("A"));
echo "<br>";
// Check age of Euro symbol (added in Unicode 2.1)
var_dump(IntlChar::charAge("?"));
echo "<br>";
// Check age of emoji (newer character)
var_dump(IntlChar::charAge("?"));
echo "<br>";
// Using integer codepoint
var_dump(IntlChar::charAge(65)); // ASCII 'A'
?>
Output
The following is the output −
array(4) { [0]=> int(1) [1]=> int(1) [2]=> int(0) [3]=> int(0) }
array(4) { [0]=> int(2) [1]=> int(1) [2]=> int(0) [3]=> int(0) }
array(4) { [0]=> int(6) [1]=> int(1) [2]=> int(0) [3]=> int(0) }
array(4) { [0]=> int(1) [1]=> int(1) [2]=> int(0) [3]=> int(0) }
Understanding the Output
The returned array represents the Unicode version as [major, minor, micro, update]. For example:
Letter 'A': [1, 1, 0, 0] means Unicode version 1.1.0.0
Euro symbol: [2, 1, 0, 0] means Unicode version 2.1.0.0
Emoji: [6, 1, 0, 0] means Unicode version 6.1.0.0
Conclusion
The IntlChar::charAge() function is useful for determining when a Unicode character was introduced, helping developers understand character compatibility across different Unicode versions.
