最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
PHP正则过滤处理微信昵称中emoji字符的方法
时间:2018-06-29 编辑:猪哥 来源:一聚教程网
本文实例讲述了PHP正则过滤处理微信昵称中emoji字符的方法。分享给大家供大家参考,具体如下:
今天刚做了一个微信应用,在获取微信昵称的过程中报错了,经查原因是微信昵称中包含emoji字符,在写入数据库的时候出错,所以想办法在写入之前把这些字符过滤掉,于是在网上找到一个方法,记录一下。
移除微信昵称中的emoji字符:
function removeEmoji($nickname) { $clean_text = ""; // Match Emoticons $regexEmoticons = '/[x{1F600}-x{1F64F}]/u'; $clean_text = preg_replace($regexEmoticons, '', $text); // Match Miscellaneous Symbols and Pictographs $regexSymbols = '/[x{1F300}-x{1F5FF}]/u'; $clean_text = preg_replace($regexSymbols, '', $clean_text); // Match Transport And Map Symbols $regexTransport = '/[x{1F680}-x{1F6FF}]/u'; $clean_text = preg_replace($regexTransport, '', $clean_text); // Match Miscellaneous Symbols $regexMisc = '/[x{2600}-x{26FF}]/u'; $clean_text = preg_replace($regexMisc, '', $clean_text); // Match Dingbats $regexDingbats = '/[x{2700}-x{27BF}]/u'; $clean_text = preg_replace($regexDingbats, '', $clean_text); return $clean_text; }
另外还发现一个github开源应用,还没有研究测试。
https://github.com/iamcal/php-emoji
补充:今天又在网上找到一个更简单的方法
// 过滤掉emoji表情 function filterEmoji($str) { $str = preg_replace_callback( '/./u', function (array $match) { return strlen($match[0]) >= 4 ? '' : $match[0]; }, $str); return $str; }
相关文章
- PHP导出数据超时的优化建议解读 10-31
- PHP之mysql位运算解析 10-31
- Laravel实现登录跳转功能解析 10-31
- php双向队列解读 10-31
- Laravel异常上下文解决教程 10-24
- php数组查询元素位置方法介绍 10-24