Hi im facing the problem at the moment to store emojis in my sql database and i think a quick solution would be to disable them from using or remove them automatically from strings.
Any way to do that?
I’m curious what the problem is with the database. If the text encoding is set up to properly handle Unicode, emojis shouldn’t pose a problem. In any event, emoji-regex looks like it might be useful to you.
Well i needed a fast solution of course i will use encoding then… i cant use unicode because my SQL Hoster doesnt allow to change the default utf8 … so encoding to base64 is the only way for me atm.
The solution with regex seems to be good ill try that out because i need to disable for usernames etc. Usernames shouldnt have emojis in my app and i want the user to dont use them.
That sounds weird to me, because UTF-8 is capable of storing Unicode. That’s its entire purpose.
@rapropos So according to this tutorial: https://mathiasbynens.be/notes/mysql-utf8mb4 i have to set up my SQL Server to this:
mysql> SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%';
+--------------------------+--------------------+
| Variable_name | Value |
+--------------------------+--------------------+
| character_set_client | utf8mb4 |
| character_set_connection | utf8mb4 |
| character_set_database | utf8mb4 |
| character_set_filesystem | binary |
| character_set_results | utf8mb4 |
| character_set_server | utf8mb4 |
| character_set_system | utf8 |
| collation_connection | utf8mb4_unicode_ci |
| collation_database | utf8mb4_unicode_ci |
| collation_server | utf8mb4_unicode_ci |
+--------------------------+--------------------+
To get this settings you also have to modifie the SQL Config like this:
[client]
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
And this is my Problem because my SQL Hoster dont provide me the Config of my SQL Server. So i cant modifiy it.
So for me my SQL Server looks now like this:
character_set_client utf8
character_set_connection utf8
character_set_database utf8mb4
character_set_filesystem binary
character_set_results utf8
character_set_server latin1
character_set_system utf8
collation_connection utf8_general_ci
collation_database utf8mb4_unicode_ci
collation_server latin1_swedish_ci
As you can see only the database itselfe is set to utf8mb4…
So if i insert Emojis now i only get “?” in my Database.
Thas why i only can encode it to base64 at the moment and save it as base64.
Im using MySQL 5.5 at the moment.
for all others i give you a hint if you want to remove emojis from strings use ng-pattern combined with a regex witch filters all utf16 characters. only allow utf8 and you are good to go