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

    1.使用正则匹配

    public  function remove_emoji($text){
            return preg_replace('/([0-9|#][x{20E3}])|[x{00ae}|x{00a9}|x{203C}|x{2047}|x{2048}|x{2049}|x{3030}|x{303D}|x{2139}|x{2122}|x{3297}|x{3299}][x{FE00}-x{FEFF}]?|[x{2190}-x{21FF}][x{FE00}-x{FEFF}]?|[x{2300}-x{23FF}][x{FE00}-x{FEFF}]?|[x{2460}-x{24FF}][x{FE00}-x{FEFF}]?|[x{25A0}-x{25FF}][x{FE00}-x{FEFF}]?|[x{2600}-x{27BF}][x{FE00}-x{FEFF}]?|[x{2900}-x{297F}][x{FE00}-x{FEFF}]?|[x{2B00}-x{2BF0}][x{FE00}-x{FEFF}]?|[x{1F000}-x{1F6FF}][x{FE00}-x{FEFF}]?/u', '', $text);
        }

    2.

     /**
        把用户输入的文本转义(主要针对特殊符号和emoji表情)
         */
        public static function filterEmoji($str){
            if(!is_string($str))return $str;
            if(!$str || $str=='undefined')return '';

            $text = json_encode($str); //暴露出unicode
            $text = preg_replace_callback("/(\u[ed][0-9a-f]{3}){2}/i",function($str){
                return "?";
            },$text); //将emoji的unicode留下,其他不动,这里的正则比原答案增加了d,因为我发现我很多emoji实际上是ud开头的,反而暂时没发现有ue开头。
            return json_decode($text);
        }
  • 相关阅读:
    mac 使用brew 安装php-redis
    thinkphp6 使用redis 实现消息队列
    Redis 桌面管理器:Another Redis Desktop Manager
    linux 查看并关闭shell脚本执行
    MySQL教程之concat以及group_concat的用法
    PHP redis 使用
    thinkphp6 command(自定义指令)
    git 使用
    linux shell中 "2>&1"含义
    linux crontab 定时任务
  • 原文地址:https://www.cnblogs.com/lixiansen/p/8400504.html
Copyright © 2011-2022 走看看