Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does PHP deal with emoji expressions in characters

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

This article will explain in detail how PHP deals with emoji expressions in characters. The content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

Catalogue

Determine whether there is an emoji expression in the string the emoji expression in the removal string the storage of the string containing the emoji expression in MySQL

Utf-8-encoded emoji emoticons or some special characters take up 4 bytes. The commonly used Chinese characters encoded by utf-8 occupy 3 bytes.

Determine whether there are emoji expressions in the string

Three PHP built-in functions:

Mb_strlenmixed mb_strlen (string $str [, string $encoding = mb_internal_encoding ()]) / / returns the number of characters contained in the string str with encoding encoding. Multibyte characters are counted as 1. / / returns FALSE if the given encoding is invalid. Mb_substrstring mb_substr (string $str, int $start [, int $length = NULL [, string $encoding = mb_internal_encoding ()]) / / performs a multi-byte secure substr () operation based on the number of characters. The position is counted from the beginning of the str. The position of the first character is 0. The position of the second character is 1. The / / mb_substr () function returns the part specified in the str based on the start and length parameters. Strlenint strlen (string $string) / / returns the length of the given string string.

Functions are as follows:

Function haveEmojiChar ($str) {$mbLen = mb_strlen ($str); $strArr = []; for ($I = 0; $I

< $mbLen; $i++) { $strArr[] = mb_substr($str, $i, 1, 'utf-8'); if (strlen($strArr[$i]) >

= 4) {return true;}} return false;}

Remove emoji emoji from a string

Functions are as follows:

Function removeEmojiChar ($str) {$mbLen = mb_strlen ($str); $strArr = []; for ($I = 0; $I

< $mbLen; $i++) { $mbSubstr = mb_substr($str, $i, 1, 'utf-8'); if (strlen($mbSubstr) >

= 4) {continue;} $strArr [] = $mbSubstr;} return implode ('', $strArr);}

Storage of strings containing emoji expressions in MySQL

1. Utf8mb4 character set is used in MySQL.

2. PHP encodes the string with base64, and decodes the string when it is extracted from the database.

3. Directly remove emoji emoticons from the string (this method is simple and rough)

So much for sharing about how PHP deals with emoji expressions in characters. I hope the above content can be of some help and learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report