voocel
2017-11-29 13:46:55 +08:00
```
/*
对 emoji 进行转义
*/
function emoji2str($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 返回
*/
function str2emoji($str){
$str_arr = explode("[[EMOJI:", $str);
$new_str = "";
foreach ($str_arr as $key => $val){
$new_str .= $val;
}
return $new_str;
}
```