zoukankan      html  css  js  c++  java
  • php 过滤emoji表情

    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;
        }
  • 相关阅读:
    bobobrowse为Lucene添加分组统计
    实现lucene检索结果排序
    facets in lucene
    lucene3.5 example
    Lucene聚类分组统计功能(grouping)
    Eclipse开发struts完全指南(三)实战
    缓存是什么?占内存吗?
    []利用memcached在多台服务器之间共享PHP的session数据
    HTML meta refresh 刷新与跳转(重定向)页面
    [置顶] 微信开发出现“该公众号暂时无法提供服务,请稍后再试”的坑
  • 原文地址:https://www.cnblogs.com/-mrl/p/5704112.html
Copyright © 2011-2022 走看看