【发布时间】:2016-08-30 12:26:37
【问题描述】:
我正在使用 twemoji 库在网页中显示表情图像。
我将"\ud83d\ude1b \ud83d\ude1b,hi"之类的代码存储在我的数据库中的消息中,现在我需要在我的网页上显示相应的表情符号。
我正在使用 PHP 脚本将 "\u1F603" 转换为 emoji:-,
$text = "This is fun \u1f602! \u1f1e8 ";
$html = preg_replace("/\\\\u([0-9A-F]{2,5})/i", "&#x$1;", $text);
echo $html;
那我就用twemoji解析body,换成emoji图标:-
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);
}
如何使用 PHP 以类似方式转换 \ud83d\ude1b \ud83d\ude1b 以在网页中显示 emoji 图标?
【问题讨论】:
-
如果
\u1F603和\xF0\x9F\x98\x83一样,那么\ud83d\ude1b \ud83d\ude1b怎么也是\xF0\x9F\x98\x83? -
@Justinas,抱歉我编辑了我的问题。
-
您提供的代码没有将
\u1F603转换为\xF0\x9F\x98\x83:sandbox.onlinephpfunctions.com/code/…