gpt4 book ai didi

php - 转变 ? ?使用 PHP 到 HTML 中的表情符号

转载 作者:可可西里 更新时间:2023-11-01 13:27:24 25 4
gpt4 key购买 nike

我们有一堆代理对(或 2 字节 utf8?)字符,例如 ��,这是作为 2 个字符存储为 UTF8 的祈祷 watch 情符号。在浏览器中呈现时,此字符串呈现为两个 ??

例子:��

我需要使用 php 将它们转换为手 emjoi,但我根本找不到 iconv、utf8_decode、html_entity_decode 等的组合来实现它。

本网站正确转换��:

http://www.convertstring.com/EncodeDecode/HtmlDecode

在其中粘贴以下字符串

请和我一起祈祷。 ��❤️

您会注意到代理对 �� (��) 转换为 🙏

这个站点声称使用 HTMLDecode,但我在 php 中找不到任何东西来实现它。我试过了:图标html_entity_decode和一些公共(public)图书馆。

我承认在转换字符编码方面我不是专家!

最佳答案

我找不到执行此操作的函数,但这个有效:

$str = "Please join me in this prayer. ��❤️";
$newStr = preg_replace_callback("/&#.....;&#.....;/", function($matches){return convertToEmoji($matches);}, $str);
print_r($newStr);
function convertToEmoji($matches){
$newStr = $matches[0];
$newStr = str_replace("&#", '', $newStr);
$newStr = str_replace(";", '##', $newStr);
$myEmoji = explode("##", $newStr);
$newStr = dechex($myEmoji[0]) . dechex($myEmoji[1]);
$newStr = hex2bin($newStr);
return iconv("UTF-16BE", "UTF-8", $newStr);
}

关于php - 转变 ? ?使用 PHP 到 HTML 中的表情符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47187165/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com