检测字符串中的图释 [英] Detect emoticons in string

查看:103
本文介绍了检测字符串中的图释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现您需要PHP 7和MySQL 5.5才能在要上载到数据库的字符串中使用图释. 我的服务器上没有这些规范,因此我想在laravel或php中给出错误消息.

I found that you need PHP 7 and MySQL 5.5 to use emoticons in a string that you want to upload to the database. I don't have these specification on my server so I want to give an error message in laravel or php.

有没有一种方法可以检测php中的图释?如果可以,那么我可以创建一个自定义验证或类似的东西吗?

Is there a way to detect emoticons in php? If so then I can create a custom validation or something like that?

我已经在Laravel中尝试过alpha_dash验证,但是不可能像这样的:-)

I've tried alpha_dash validation in Laravel but then it isn't possible to do one old-school like this one :-)

推荐答案

在Johannes回答之后,我在某个论坛的某个地方找到了解决方案.这个正则表达式可以达到目的:)

To follow on from Johannes answer I found a solution on a forum somewhere. This regex does the trick :)

    $unicodeRegexp = '([*#0-9](?>\\xEF\\xB8\\x8F)?\\xE2\\x83\\xA3|\\xC2[\\xA9\\xAE]|\\xE2..(\\xF0\\x9F\\x8F[\\xBB-\\xBF])?(?>\\xEF\\xB8\\x8F)?|\\xE3(?>\\x80[\\xB0\\xBD]|\\x8A[\\x97\\x99])(?>\\xEF\\xB8\\x8F)?|\\xF0\\x9F(?>[\\x80-\\x86].(?>\\xEF\\xB8\\x8F)?|\\x87.\\xF0\\x9F\\x87.|..(\\xF0\\x9F\\x8F[\\xBB-\\xBF])?|(((?<zwj>\\xE2\\x80\\x8D)\\xE2\\x9D\\xA4\\xEF\\xB8\\x8F\k<zwj>\\xF0\\x9F..(\k<zwj>\\xF0\\x9F\\x91.)?|(\\xE2\\x80\\x8D\\xF0\\x9F\\x91.){2,3}))?))';

这篇关于检测字符串中的图释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆