那是 UTF-16BE(最重要的位在前),而不是 LE(另请参见UTF-16 示例)。
// Hexadecimal text: each 2 characters describe 1 byte
$sText= '007A006E0061006B006F007600690020010D0107017E0020006800610068006100730068';
// Actually forming bytes of that text, i.e. making '7A' a 'z' and '20' a ' '
$sUtf16= pack( 'H*', $sText );
如果你真的需要 UTF-8:
// Since we now have an actual encoding: convert it to the wanted one
$sUtf8= mb_convert_encoding( $sUtf16, 'UTF-8', 'UTF-16BE' );
// To make sure the consumer interpretes the data correctly
header( 'Content-type: text/plain; charset=UTF-8' );
echo $sUtf8;
但是如果客户端无论如何都能够处理不同的编码(例如互联网浏览器),您可以立即输出 UTF-16BE:
header( 'Content-type: text/html; charset=UTF-16BE' );
echo $sUtf16;
此代码甚至可以与 PHP5 一起使用,并且不需要额外的扩展。