| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\utils;
- /**
- * @property Store $store
- */
- class Emoji
- {
- public static function emoji($input)
- {
- $output = "";
- if(strpos($input,'[[EMOJI:') !== false)
- {
- $output = Emoji::emoji_decode($input);
- }
- else
- {
- $output = Emoji::emoji_encode($input);
- }
- return $output;
- }
- //对emoji表情转义
- public static function emoji_encode($str)
- {
- $strEncode = '';
- $length = mb_strlen($str,'utf-8');
- for ($i=0; $i < $length; $i++)
- {
- $_tmpStr = mb_substr($str,$i,1,'utf-8');
- if (strlen($_tmpStr) >= 4)
- {
- $strEncode .= '[[EMOJI:'.rawurlencode($_tmpStr).']]';
- }
- else
- {
- $strEncode .= $_tmpStr;
- }
- }
- return $strEncode;
- }
- //对emoji表情转反义
- public static function emoji_decode($str)
- {
- $strDecode = preg_replace_callback('|\[\[EMOJI:(.*?)\]\]|', function($matches){
- return rawurldecode($matches[1]);
- }, $str);
- return $strDecode;
- }
- }
|