PHP-将字符串转换为unicode [英] PHP - Convert string to unicode
本文介绍了PHP-将字符串转换为unicode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在处理
$source = mb_convert_encoding('test', "unicode", "utf-8");
$source = unpack('C*', $source);
var_dump($source);
返回:
array (size=8)
1 => int 0
2 => int 116
3 => int 0
4 => int 101
5 => int 0
6 => int 115
7 => int 0
8 => int 116
但我想要此返回值:
array (size=8)
1 => int 116
2 => int 0
3 => int 101
4 => int 0
5 => int 115
6 => int 0
7 => int 116
8 => int 0
我想在openssl函数中使用此返回值进行加密。只是 $ source
对我很重要,我编写了其他代码进行调试。
I want use this return in openssl function for encryption. just $source
important to me, i write other code for debugging.
我该怎么办才能解决此问题?
What can i do to solve this problem?
推荐答案
Unicode不是真正的编码;它是总体标准的名称,主要由Microsoft用作UTF-16BE的别名,显然,PHP为此支持它。您期望的是UTF-16LE,因此请明确使用它:
"Unicode" is not a real encoding; it's the name of the overarching standard and used as an alias for UTF-16BE mostly by Microsoft, and apparently PHP supports it for that reason. What you expect is UTF-16LE, so use that explicitly:
$source = mb_convert_encoding('test', 'UTF-16LE', 'UTF-8');
这篇关于PHP-将字符串转换为unicode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文