Php 如何将\ud83d\ude1b转换为显示表情符号?

Php 如何将\ud83d\ude1b转换为显示表情符号?,php,html,Php,Html,我正在使用twemoji库在网页中显示表情图片 我在数据库中的消息中存储了类似“\ud83d\ude1b\ud83d\ude1b,hi”的代码,现在我需要在网页上显示相应的表情符号 我正在使用PHP脚本将“\u1F603”转换为表情符号:- $text = "This is fun \u1f602! \u1f1e8 "; $html = preg_replace("/\\\\u([0-9A-F]{2,5})/i", "&#x$1;", $text); echo $html; 然后,我使

我正在使用twemoji库在网页中显示表情图片

我在数据库中的消息中存储了类似
“\ud83d\ude1b\ud83d\ude1b,hi”
的代码,现在我需要在网页上显示相应的表情符号

我正在使用PHP脚本将
“\u1F603”
转换为表情符号:-

$text = "This is fun \u1f602! \u1f1e8 ";
$html = preg_replace("/\\\\u([0-9A-F]{2,5})/i", "&#x$1;", $text);
echo $html;
然后,我使用解析主体并将其替换为表情符号图标:-

window.onload = function() {

  // Set the size of the rendered Emojis
  // This can be set to 16x16, 36x36, or 72x72
  twemoji.size = '16x16';

  // Parse the document body and
  // insert <img> tags in place of Unicode Emojis
  codePoint = twemoji.convert.toCodePoint($('.com-text').html());
  twemoji.parse(document.body);

}
window.onload=function(){
//设置渲染表情的大小
//这可以设置为16x16、36x36或72x72
twemoji.size='16x16';
//解析文档体和
//插入标记以代替Unicode表情符号
codePoint=twemoji.convert.toCodePoint($('.com text').html());
parse(document.body);
}
如何使用PHP在网页中显示表情符号图标,以类似的方式转换
\ud83d\ude1b\ud83d\ude1b

留出两个问题(和),我设法编写了这段代码(似乎不适用于您的示例):


如果
\u1F603
\xF0\x9F\x98\x83
相同,那么
\ud83d\ude1b\ud83d\ude1b
也应该是
\xF0\x9F\x98\x83
?@Justinas,很抱歉我编辑了我的问题。您提供的代码没有将
\u1F603
转换为
\xF0\x9F\x98\x83
:如果
\u1F603与
相同,比
\ud83d\ude1b\ud83d\ude1b
如何也
\xF0\x9F\x98\x83
?@Justinas,对不起,我编辑了我的问题。您提供的代码不会将
\u1F603
转换为
\xF0\x9F\x98\x83
:在我的问题中,我的db将数据存储在UTF16代理项对中,如
\ud83d\ud1b
。我需要将其转换为表情符号。在我的问题中,我的db将数据存储在UTF16代理项对中,如
\ud83d\ude1b
。我需要把它转换成表情符号。
echo preg_replace_callback(
    "/./", // for every symbol
    function($matched) {
        return '\x'.dechex(ord($matched[0]));
    },
    json_decode('"\u1F603"') // convert Unicode to text
);