preg_match_all('/\[\[EMOJI:(.*?)\]\]/',$data['content'],$arr_content);//过滤掉emoji表情
foreach($arr_content[0] as $k=>$v){
$emoji = str2emoji($v);
$data['content'] = str_replace($v,$emoji,$data['content']);
}
function emoji2str($str){
$strEncode = '';
$length = ($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表情的PHP代码。通过使用正则表达式preg_match_all过滤并替换emoji,确保了文本的正确显示。代码首先匹配并捕获emoji,然后使用自定义函数str2emoji进行转换。
765

被折叠的 条评论
为什么被折叠?



