【问题标题】:PHP - Convert string to unicodePHP - 将字符串转换为 unicode
【发布时间】:2014-11-02 18:16:18
【问题描述】:

我正在努力

$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 对我很重要,我编写了其他代码进行调试。

我能做些什么来解决这个问题?

【问题讨论】:

    标签: php unicode converter


    【解决方案1】:

    “Unicode”不是真正的编码;它是总体标准的名称,主要由 Microsoft 用作 UTF-16BE 的别名,显然 PHP 出于这个原因支持它。您期望的是 UTF-16LE,因此请明确使用它:

    $source = mb_convert_encoding('test', 'UTF-16LE', 'UTF-8');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-06-09
      • 2018-09-18
      • 1970-01-01
      • 2011-05-14
      • 2016-11-03
      • 1970-01-01
      相关资源
      最近更新 更多