Home >Backend Development >PHP Tutorial >How to Convert Unicode Numeric Values to PHP Strings?
Question:
How can PHP create strings that contain individual Unicode characters specified by their "Unicode numeric values"?
Answer:
Prior to PHP 7.0.0, this task required the use of the mb_convert_encoding function. However, PHP 7.0.0 introduced the "Unicode codepoint escape" syntax, which allows direct conversion of Unicode numeric values into PHP strings:
$unicodeChar = "\u{1000}";
This notation creates a string containing a single Unicode character whose Unicode numeric value is 1000 (4096 in decimal).
Example:
// PHP 5.x $unicodeChar = mb_convert_encoding pack('H*', '1000'), 'UTF-8', 'UTF-16BE'); // PHP 7.0+ $unicodeChar = "\u{1000}"; echo "Unicode character: $unicodeChar\n"; // Outputs: "Ѐ"
The above is the detailed content of How to Convert Unicode Numeric Values to PHP Strings?. For more information, please follow other related articles on the PHP Chinese website!