Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/247.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用UTF-16十进制php打印表情符号_Php_Php 7 - Fatal编程技术网

使用UTF-16十进制php打印表情符号

使用UTF-16十进制php打印表情符号,php,php-7,Php,Php 7,所以目前我有一个UTF-16十进制的字符串,我正在使用chr()转换它 它在大多数情况下工作正常,但在表情符号上却失败了 我在js中运行了一个完美的例子,下面就是这个例子 console.log(String.fromCharCode(84,104,105,115,32,105,115,32,97,32,116,101,115,116,32,119,105,116,104,32,97,110,32,101,109,111,106,105,32,55357,56834,32)) 产生 This

所以目前我有一个UTF-16十进制的字符串,我正在使用chr()转换它

它在大多数情况下工作正常,但在表情符号上却失败了

我在js中运行了一个完美的例子,下面就是这个例子

console.log(String.fromCharCode(84,104,105,115,32,105,115,32,97,32,116,101,115,116,32,119,105,116,104,32,97,110,32,101,109,111,106,105,32,55357,56834,32))
产生

This is a test with an emoji I managed to get it working this way

echo utf16HexToUtf8("005400680069007300200069007300200061002000740065007300740020007700690074006800200061006E00200065006D006F006A00690020D83DDE020020");

function utf16HexToUtf8($data){
    return preg_replace_callback('/(d[89ab][0-9a-f]{2})(d[c-f][0-9a-f]{2})|([0-9a-fA-F]{4})/i', function ($matches) {
        return mb_convert_encoding( hex2bin($matches[0]), 'UTF-8', 'UTF-16');
    }, $data);
}

这是一个带有表情符号的测试我设法让它以这种方式工作

输出:


这是一个带有表情符号的测试我设法让它以这种方式工作

输出:


这是一个表情符号测试,为什么不使用UTF-8呢?这将使事情变得相当容易。例如,
echo mb_chr(128514)也很遗憾,我没有选择使用UTF-8,我必须使用的数据是UTF-16。你能描述一下这是什么数据吗?因为这听起来几乎是不可想象的事情,此时需要UTF16数据。那么为什么不使用UTF-8呢?这将使事情变得相当容易。例如,
echo mb_chr(128514)也很遗憾,我没有选择使用UTF-8,我必须使用的数据是UTF-16。你能描述一下这是什么数据吗?因为这听起来几乎是不可想象的事情,此时此刻需要UTF16数据。不要重新发明轮子,存在,它存在的全部原因是将一种文本编码转换成另一种。不要重新发明轮子,存在,它存在的全部原因是将一种文本编码转换成另一种。