S
S
SlavaMorg2020-09-09 10:09:41
PHP
SlavaMorg, 2020-09-09 10:09:41

What is the best way to check a string for emojis (PHP + MySQL)?

There is a site on Bitrix (but this is not very important). DB - MySQL.
When saving text to the database, the text is cut off. This happens because there are emoji. As I understand it, in the database this field has utf8_unicode_ci encoding, and the emoji code is out of this range. As a result, either the database or Bitrix cut the string down to the emoji. Task: warn the user that there are emoji in the line so that he deletes them. The specifics are such that they are not really needed there. They do not need to be replaced automatically. We need a stupid function that will tell if there are emojis in the string or not. You cannot change the field type in the database. Matching each character in a line with a huge array of smileys (there are a lot of them) is also not an option. Is there any other way? I only find functions that simply determine whether it is utf8 or not, and I'm interested in a subset.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
FanatPHP, 2020-09-09
@FanatPHP

Of course, I'm not a specialist in Bitrix, but is it really impossible to use a normal encoding that supports all characters, utf8mb4?

N
nokimaro, 2020-09-10
@nokimaro

https://github.com/aaronpk/emoji-detector-php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question