PHP - 将 unicode 转换为字符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7274183/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP - convert unicode to character
提问by jazz
Possible Duplicate:
How to get the character from unicode value in PHP?
PHP: Convert unicode codepoint to UTF-8
How can I convert a unicode character such as %u05E1
to a normal character via PHP?
如何%u05E1
通过 PHP将 unicode 字符(例如)转换为普通字符?
The chr
function not covering it and I am looking for something similar.
该chr
功能不会覆盖它,我期待类似的东西。
回答by deceze
"%uXXXX" is a non-standard scheme for URL-encoding Unicode characters. Apparently it was proposed but never really used. As such, there's hardly any standard function that can decode it into an actual UTF-8 sequence.
"%uXXXX" 是用于 URL 编码 Unicode 字符的非标准方案。显然它被提议但从未真正使用过。因此,几乎没有任何标准函数可以将其解码为实际的 UTF-8 序列。
It's not too difficult to do it yourself though:
不过,自己做并不难:
$string = '%u05E1%u05E2';
$string = preg_replace('/%u([0-9A-F]+)/', '&#x;', $string);
echo html_entity_decode($string, ENT_COMPAT, 'UTF-8');
This converts the %uXXXX
notation to HTML entity notation &#xXXXX;
, which can be decoded to actual UTF-8 by html_entity_decode
. The above outputs the characters "??" in UTF-8 encoding.
这会将%uXXXX
表示法转换为 HTML 实体表示法&#xXXXX;
,它可以通过html_entity_decode
. 以上输出字符“??” UTF-8 编码。