Php 如何将\x格式的UTF-8字符串解码为Unicode?

Php 如何将\x格式的UTF-8字符串解码为Unicode?,php,unicode,encoding,Php,Unicode,Encoding,我有以下格式的Unicode字符串: $str = '\x576879204920616d'; 我知道它解析为Unicode中的以下单词: Why I am 但我不知道如何在PHP中实现它 顺便说一句,我知道这是可以做到的。我使用过其中一个在线网站,它可能: 删除无意义的内容并从十六进制转换 $in = '\x576879204920616d'; $out = hex2bin(substr($in,2)); var_dump($out); // string(8) "Why I am"

我有以下格式的Unicode字符串:

$str = '\x576879204920616d';
我知道它解析为Unicode中的以下单词:

Why I am
但我不知道如何在PHP中实现它

顺便说一句,我知道这是可以做到的。我使用过其中一个在线网站,它可能:


删除无意义的内容并从十六进制转换

$in = '\x576879204920616d';
$out = hex2bin(substr($in,2));

var_dump($out); // string(8) "Why I am"

我不知道是什么产生了这种输出格式,但它只是通用的十六进制编码,与UTF8或Unicode没有任何关系。

删去无意义的内容并从十六进制转换

$in = '\x576879204920616d';
$out = hex2bin(substr($in,2));

var_dump($out); // string(8) "Why I am"

我不知道是什么产生了这种输出格式,但它只是通用的十六进制编码,与UTF8或Unicode无关。

使用UTF-16BE(big-endian)和Unicode码点之间的直接映射

   $str = '\x576879204920616d'; 
   echo mb_convert_encoding($str, 'UTF-8', 'UTF-16BE');

使用UTF-16BE(big-endian)和Unicode代码点之间的直接映射

   $str = '\x576879204920616d'; 
   echo mb_convert_encoding($str, 'UTF-8', 'UTF-16BE');

它来自Python脚本,该脚本通过首先编码字符串将字符串以各种编码保存到DB中:str.encode('UTF-8','subrogatepass')@jjj这听起来像Postgres编码问题。我见过postgres显示这样完全有效的数据,因为指定的编码不正确。它来自Python脚本,该脚本通过首先编码字符串将字符串以各种编码保存到DB中:str.encode('UTF-8','subrogatepass')@jjj这听起来像postgres编码问题。我见过postgres显示这样完全有效的数据,因为指定的编码不正确。