PHP - Convert string to unicode

▼魔方 西西 提交于 2020-05-15 19:13:37

问题


I'm working on it

$source = mb_convert_encoding('test', "unicode", "utf-8");
$source = unpack('C*', $source);
var_dump($source);

return:

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

but i want this return:

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

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?


回答1:


"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');


来源:https://stackoverflow.com/questions/25742700/php-convert-string-to-unicode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!