問題描述
這個問題看起來很簡單,但我一直沒能找到答案.
This question looks embarrassingly simple, but I haven't been able to find an answer.
與以下 C# 代碼行等效的 PHP 是什么?
What is the PHP equivalent to the following C# line of code?
string str = "u1000";
此示例使用單個 Unicode 字符創建一個字符串,該字符的Unicode 數值"為是 1000
十六進制(4096
十進制).
This sample creates a string with a single Unicode character whose "Unicode numeric value" is 1000
in hexadecimal (4096
in decimal).
也就是說,在 PHP 中,如何使用單個 Unicode 字符創建一個字符串,該字符的Unicode 數值"為知道嗎?
That is, in PHP, how can I create a string with a single Unicode character whose "Unicode numeric value" is known?
推薦答案
因為 JSON 直接支持 uxxxx
語法我首先想到的是:
Because JSON directly supports the uxxxx
syntax the first thing that comes into my mind is:
$unicodeChar = 'u1000';
echo json_decode('"'.$unicodeChar.'"');
另一種選擇是使用 mb_convert_encoding()
echo mb_convert_encoding('က', 'UTF-8', 'HTML-ENTITIES');
或者利用 UTF-16BE(大端)和 Unicode 代碼點之間的直接映射:
or make use of the direct mapping between UTF-16BE (big endian) and the Unicode codepoint:
echo mb_convert_encoding("x10x00", 'UTF-8', 'UTF-16BE');
這篇關于PHP 字符串中的 Unicode 字符的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!