博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
php 过滤emoji表情
阅读量:4672 次
发布时间:2019-06-09

本文共 2280 字,大约阅读时间需要 7 分钟。

function yz_expression(){		foreach ($_POST as $key => &$value) {		$value = preg_replace_callback('/[\xf0-\xf7].{3}/', function($r) { return '@E' . base64_encode($r[0]);},$value);			$countt=substr_count($value,"@");			for ($i=0; $i < $countt; $i++) {				$c = stripos($value,"@");				$value=substr($value,0,$c).substr($value,$c+10,strlen($value)-1);			}			$value = preg_replace_callback('/@E(.{6}==)/', function($r) {return base64_decode($r[1]);}, $value);		}		return $_POST;}

 

/**     * 替换掉数组中的emoji表情     * @param $arrayString     * @param string $replaceTo     * @return mixed|string     */    public static function filterEmojiDeep($arrayString,$replaceTo = '?')    {        if(is_string($arrayString))        {            return self::filterEmoji($arrayString,$replaceTo);        }        else if(is_array($arrayString))        {            foreach($arrayString as &$array)            {                if(is_array($array) || is_string($array))                {                    $array = self::filterEmojiDeep($array,$replaceTo);                }                else                {                    $array = $array;                }            }        }        return $arrayString;    }/**     * 替换掉emoji表情     * @param $text     * @param string $replaceTo     * @return mixed|string     */    public static function filterEmoji($text, $replaceTo = '?')    {        $clean_text = "";        // Match Emoticons        $regexEmoticons = '/[\x{1F600}-\x{1F64F}]/u';        $clean_text = preg_replace($regexEmoticons, $replaceTo, $text);        // Match Miscellaneous Symbols and Pictographs        $regexSymbols = '/[\x{1F300}-\x{1F5FF}]/u';        $clean_text = preg_replace($regexSymbols, $replaceTo, $clean_text);        // Match Transport And Map Symbols        $regexTransport = '/[\x{1F680}-\x{1F6FF}]/u';        $clean_text = preg_replace($regexTransport, $replaceTo, $clean_text);        // Match Miscellaneous Symbols        $regexMisc = '/[\x{2600}-\x{26FF}]/u';        $clean_text = preg_replace($regexMisc, $replaceTo, $clean_text);        // Match Dingbats        $regexDingbats = '/[\x{2700}-\x{27BF}]/u';        $clean_text = preg_replace($regexDingbats, $replaceTo, $clean_text);        return $clean_text;    }

 

转载于:https://www.cnblogs.com/-mrl/p/5704112.html

你可能感兴趣的文章
VS2010中dumpbin工具的使用
查看>>
使用Golang搭建web服务
查看>>
HTML5触摸事件(touchstart、touchmove和touchend)
查看>>
架构师软技能之协商(上)
查看>>
商品翻牌效果(纯css)
查看>>
win10 UWP 序列化
查看>>
读书心得
查看>>
前端知识整理 CSS盒模型
查看>>
sendmail 常见报错总结
查看>>
asp.net Response.AddHeader的方法来下载
查看>>
neo4j-访问提示No authorization header supplied.
查看>>
android-activity生命周期方法
查看>>
基于贪心算法的几类区间覆盖问题 nyoj 12喷水装置(二) nyoj 14会场安排问题...
查看>>
web之JavaScript
查看>>
HTML input 控件
查看>>
MongoDB副本集配置系列六:定位MongoDB慢的原因
查看>>
[EGORefreshTableHeaderView]手动启动下拉更新的方法
查看>>
Linux磁盘分区/格式化/挂载目录
查看>>
raspberry pi下使用mp3blaster播放mp3音乐
查看>>
[转]win7 64位下android开发环境的搭建
查看>>