PHP实现-移除Emoji表情

2018-03-21 19:57 By "Powerless" 2914 0 1

/**
 * 过滤表情
 * @param string $str 要过滤的字符串
 */
function filterEmoji($str)
{
    $str = preg_replace_callback(
        '/./u',
        function (array $match) {
            return strlen($match[0]) >= 4 ? '' : $match[0];
        },
        $str);

    return $str;
}

如果仅仅使用前端输入处过滤未免有不是很安全,所以有了这个方法

评 论

View in WeChat

Others Discussion

  • 浏览器访问网站经历的步骤-Html
    Posted on 2018-11-28 18:48
  • BASE原则
    Posted on 2020-12-17 16:42
  • 程序员年中考试题-段子版
    Posted on 2021-06-23 15:57
  • 前端知识体系精简-Css
    Posted on 2018-03-28 18:34
  • Mysql联合索引的最左前缀匹配原则
    Posted on 2018-08-25 15:00
  • 2016年云计算热词
    Posted on 2019-06-12 17:53
  • PHP没你想的那么差
    Posted on 2021-12-17 15:40
  • 分布式架构之「 数据分布」
    Posted on 2019-11-14 10:00