我们在通过php获取微信昵称,并且存于数据库的时候,由于一些昵称带有特殊符号,所以存不进去,这时候我们可以通过下面的方式来处理。
方法二
protected function removeemoji($clean_text) { // match emoticons $regexemoticons = '/[\\\\x{1f600}-\\\\x{1f64f}]/u'; $clean_text = preg_replace($regexemoticons, '', $clean_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;}方法二
preg_replace("/[\\\\x{1f600}-\\\\x{1f64f}\\\\x{1f300}-\\\\x{1f5ff}\\\\x{1f680}-\\\\x{1f6ff}\\\\x{2600}-\\\\x{26ff}\\\\x{2700}-\\\\x{27bf}]/u","","这里是昵称")方法三
// 过滤掉emoji表情function filteremoji($str){ $str = preg_replace_callback( '/./u', function (array $match) { return strlen($match[0]) >= 4 ? '' : $match[0]; }, $str); return $str;}相关学习推荐:php编程从入门到精通
阿里云服务器配置为域控美国地 无法访问-虚拟主机/数据库问题云服务器怎么加输入法云南ubuntuftp服务器租用虚拟主机台湾服务器用不用备案云服务器上海ecs云服务器备份数据天猫去年双11退货率 仅为6.1%解析不能生效-企业邮局