php emoji expression processing
背景
移动设备经常会发生用户发送的内容中包含emoji表情,未经处理,在显示时就是乱码。
解决方案
1.数据库支持:将Mysql的编码从utf8转换成utf8mb4。
2.匹配出内容中的emoji表情做过滤或替换
/** * 表情转换 更新到ios9.2涵盖编码范围 * @param $str * @return mixed */ public static function emoji_to_html($str) { $regex = '/([0-9|#][\x{20E3}])|[\x{00ae}|\x{00a9}|\x{203C}|\x{2047}|\x{2048}|\x{2049}|\x{3030}|\x{303D}|\x{2139}|\x{2122}|\x{3297}|\x{3299}][\x{FE00}-\x{FEFF}]?|[\x{2190}-\x{21FF}][\x{FE00}-\x{FEFF}]?|[\x{2300}-\x{23FF}][\x{FE00}-\x{FEFF}]?|[\x{2460}-\x{24FF}][\x{FE00}-\x{FEFF}]?|[\x{25A0}-\x{25FF}][\x{FE00}-\x{FEFF}]?|[\x{2600}-\x{27BF}][\x{FE00}-\x{FEFF}]?|[\x{2900}-\x{297F}][\x{FE00}-\x{FEFF}]?|[\x{2B00}-\x{2BF0}][\x{FE00}-\x{FEFF}]?|[\x{1F000}-\x{1F6FF}][\x{FE00}-\x{FEFF}]?|[\x{1F900}-\x{1F9FF}][\x{FE00}-\x{FEFF}]?/u'; $str = preg_replace_callback($regex,function($matches){ $str = json_encode($matches[0]); $str = '<em data-emoji=' . str_replace('\u', 'em:', $str) . '></em>'; return $str; },$str); return $str; } 从数据库取出后再转回 $string = preg_replace_callback('/<em data-emoji=\"(.*?)\"><\/em>/is', "self::preg_emoji", $string); /** * 输出emoji表情 * @param $matches * @return mixed */ public static function preg_emoji($matches) { $str = $matches[0]; $str = str_replace('em:', '\u', $str); return $str; }
/** * 过滤表情 * @param $str * @return mixed */ public static function filter_emoji($str) { $regex = '/(\\\u[ed][0-9a-f]{3})/i'; $str = json_encode($str); $str = preg_replace($regex, '', $str); return json_decode($str); }
以上就介绍了php emoji表情处理,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

According to reports on January 26, according to foreign technology media emojipedia, in the iOS 17.4 Beta 1 update released today, in addition to major improvements such as sideloading and third-party app stores for testing in 27 EU countries, Apple has also added several new Emoji. The iOS 17.4 Beta 1 update adds phoenix, lime, smiling faces shaking their heads up and down, and a series of character emoticons that point the way, from the Emoji 15.1 update proposed by Unicode in September 2023. The complete Emoji are attached as follows: This update adds a total of 118 Emojis, including 6 new Emojis and 4 gender-neutral family Emojis. In addition, there are 6 existing character expressions

Emoji emoticons are the latest input method function added to Win10 Education Edition. Many cute emoticons make chatting less boring. However, some users will pop up this interface when using shortcut keys. Today I will show you how to turn off emoji in Win10 Education Edition. introduce. How to turn off emoji1 in Win10 Education Edition. First, you need to right-click the input method on the right side of the taskbar below. 2. Select Settings in the pop-up option box to enter the language setting interface. 3. Select the "Keys" option in the interface and scroll to the bottom to find "Open Emoticons and Symbols Panel", where you can turn off emoji expressions. 4. If other input methods are installed, you can enter the "Settings and Language" interface from Windows settings, and then select

Huawei emoji input method: 1. Huawei mobile phones come with an emoji keyboard. You can switch to this keyboard to enter emoji when entering text; 2. Where you need to enter emoji, long press the input box, and then select "Enter" "Method Settings", in the input method settings, you can find and select the emoji input method that comes with the system; 3. You can download and use a third-party emoji keyboard, and then browse and select the emoji you want to use on the keyboard. .

Apple has officially launched iOS 15.4 and iPadOS 15.4 Beta 1 to the public, version 19E5209h. The official update notes list many changes, including the addition of new features. Support for masks Face ID Apple has added “Mask Face ID” in iOS 15.4. The iPhone will authenticate users by identifying the unique characteristics of the area around the eyes when wearing a mask. Note that users must use iPhone 12 or above to use this feature. Adding 112 new Emoji expressions iOS 15.4 Beta 1 officially supports Emoji 14. Add to it

Solution to the garbled mysql emoji code: 1. Check the mysql table encoding through the "show create table test ENGINE=InnoDB DEFAULT CHARSET=utf8mb4" command; 2. Set the reading encoding to "utf8mb4" through "set names utf8mb4;"

What are the similarities and differences between __str__ and __repr__? We all know the representation of strings. Python's built-in function repr() can express objects in the form of strings to facilitate our identification. This is the "string representation". repr() obtains the string representation of an object through the special method __repr__. If __repr__ is not implemented, when we print an instance of a vector to the console, the resulting string may be. >>>classExample:pass>>>print(str(Example()))>>>

1The basic unit of Unicode computer storage is the byte, which is composed of 8 bits. Since English only consists of 26 letters plus a number of symbols, English characters can be stored directly in bytes. But other languages (such as Chinese, Japanese, Korean, etc.) have to use multiple bytes for encoding due to the large number of characters. With the spread of computer technology, non-Latin character encoding technology continues to develop, but there are still two major limitations: no multi-language support: the encoding scheme of one language cannot be used in another language and there is no unified standard: for example There are many encoding standards in Chinese such as GBK, GB2312, GB18030, etc. Since the encoding methods are not unified, developers need to convert back and forth between different encodings, and many errors will inevitably occur.

Apple pushes iOS15.4Beta5 and iPadOS15.4Beta5 to developers. It is estimated that this may be the final Beta. It is likely to enter the RC stage next week, and the official version will be released before mid-March. AirTag anti-tracking function The new version of iOS 15.4 introduces the AirTag and FindMy anti-tracking functions previously announced by Apple. Now they have been introduced in Beta 4, adding warning messages and adjusting the "unknown accessories detected" warning during pairing design. Siri’s new voice option For American users, iOS15.4Beta4 has added the fifth Siri voice (file name: Quinn).
