You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

19 lines
476 B

  1. <?php
  2. namespace Kuxin\Helper;
  3. class Emoji
  4. {
  5. public static function encode($text)
  6. {
  7. $tmpStr = json_encode($text); //暴露出unicode
  8. $tmpStr = preg_replace("#(\\\ue[0-9a-f]{3})#ie", "addslashes('\\1')", $tmpStr); //将emoji的unicode留下,其他不动
  9. return json_decode($tmpStr);
  10. }
  11. public static function decode($text)
  12. {
  13. preg_replace("#\\\u([0-9a-f]+)#ie", "iconv('UCS-2','UTF-8', pack('H4', '\\1'))", $text);
  14. }
  15. }