如何用PHP解析微信中改写后的长尾词emoji表情?

2026-04-05 05:408阅读0评论SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计266个文字,预计阅读时间需要2分钟。

如何用PHP解析微信中改写后的长尾词emoji表情?

请引入php-emoji库,主要方法是解析。但发送功能还没做好,需要支持ubb编辑器,我会继续改进。以下是转换得到包含emoji表情的代码:

phpfunction parseHtmlemoji($text) { require_once 'emoji/emoji.php';}

请引入php-emoji
主要方法就是解析 但发送还没做好,需要ubb编辑器支持,这个我还会改进

//转换得到含emoji表情的代码 注意引入css文件 function parseHtmlemoji ($text) { require_once 'emoji/emoji.php'; $tmpStr = json_encode($text); $tmpStr = preg_replace("#(\\ue[0-9a-f]{3})#ie", "addslashes('\\1')", $tmpStr); $text = json_decode($tmpStr); preg_match_all("#u([0-9a-f]{4})+#iUs", $text, $rs); if (empty($rs[1])) { return $text; } foreach ($rs[1] as $v) { $test_iphone = '0x' . trim(strtoupper($v)); $test_iphone = $test_iphone + 0; $t = emoji_unified_to_html( emoji_softbank_to_unified(utf8_bytes($test_iphone))); $text = str_replace("\\u$v", $t, $text); } return $text; } function utf8_bytes ($cp) { if ($cp > 0x10000) { # 4 bytes return chr(0xF0 | (($cp & 0x1C0000) >> 18)) . chr(0x80 | (($cp & 0x3F000) >> 12)) . chr(0x80 | (($cp & 0xFC0) >> 6)) . chr(0x80 | ($cp & 0x3F)); } else if ($cp > 0x800) { # 3 bytes return chr(0xE0 | (($cp & 0xF000) >> 12)) . chr(0x80 | (($cp & 0xFC0) >> 6)) . chr(0x80 | ($cp & 0x3F)); } else if ($cp > 0x80) { # 2 bytes return chr(0xC0 | (($cp & 0x7C0) >> 6)) . chr(0x80 | ($cp & 0x3F)); } else { # 1 byte return chr($cp); } }

如何用PHP解析微信中改写后的长尾词emoji表情?

本文共计266个文字,预计阅读时间需要2分钟。

如何用PHP解析微信中改写后的长尾词emoji表情?

请引入php-emoji库,主要方法是解析。但发送功能还没做好,需要支持ubb编辑器,我会继续改进。以下是转换得到包含emoji表情的代码:

phpfunction parseHtmlemoji($text) { require_once 'emoji/emoji.php';}

请引入php-emoji
主要方法就是解析 但发送还没做好,需要ubb编辑器支持,这个我还会改进

//转换得到含emoji表情的代码 注意引入css文件 function parseHtmlemoji ($text) { require_once 'emoji/emoji.php'; $tmpStr = json_encode($text); $tmpStr = preg_replace("#(\\ue[0-9a-f]{3})#ie", "addslashes('\\1')", $tmpStr); $text = json_decode($tmpStr); preg_match_all("#u([0-9a-f]{4})+#iUs", $text, $rs); if (empty($rs[1])) { return $text; } foreach ($rs[1] as $v) { $test_iphone = '0x' . trim(strtoupper($v)); $test_iphone = $test_iphone + 0; $t = emoji_unified_to_html( emoji_softbank_to_unified(utf8_bytes($test_iphone))); $text = str_replace("\\u$v", $t, $text); } return $text; } function utf8_bytes ($cp) { if ($cp > 0x10000) { # 4 bytes return chr(0xF0 | (($cp & 0x1C0000) >> 18)) . chr(0x80 | (($cp & 0x3F000) >> 12)) . chr(0x80 | (($cp & 0xFC0) >> 6)) . chr(0x80 | ($cp & 0x3F)); } else if ($cp > 0x800) { # 3 bytes return chr(0xE0 | (($cp & 0xF000) >> 12)) . chr(0x80 | (($cp & 0xFC0) >> 6)) . chr(0x80 | ($cp & 0x3F)); } else if ($cp > 0x80) { # 2 bytes return chr(0xC0 | (($cp & 0x7C0) >> 6)) . chr(0x80 | ($cp & 0x3F)); } else { # 1 byte return chr($cp); } }

如何用PHP解析微信中改写后的长尾词emoji表情?