Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
640 views
in Technique[技术] by (71.8m points)

php - Detect emoticons in string

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.

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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\x8Fk<zwj>\xF0\x9F..(k<zwj>\xF0\x9F\x91.)?|(\xE2\x80\x8D\xF0\x9F\x91.){2,3}))?))';

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...