ellisio's avatar

Working with Unicode Emoji from iOS.

Hello,

So this week I was presented with a rather complex scenario that I wish never landed on my lap... That is to store emoji unicode characters for an iOS app via our Laravel API. By default, Laravel uses utf8 encoding with utf8_general_ci collation. Because the emojis are 4-bytes, and not 3-bytes, utf8 does not work.

The solution we came up with was to use utf8mb4 and utf8mb4_unicode_ci for our schemas. Because of this, I also found that all my VARCHAR fields can not be greater than 191. So in my migrations I have to change all:

->string('field')

To:

->string('field', 191)

Thankfully we caught this in early development, so I didn't have to worry about the whole upgrading the database from utf8 to utf8mb4 scenario.

The point of this thread is to ask anyone reading this if they have had to deal with emojis themselves. What was your solution to the problem? Did you resort to 100% utf8mb4 as well?

Cheers,
-Andrew

0 likes
2 replies
vilim67's avatar

Hello, did you maybe have a situation where you have to insert emoticon/emoji from PHP. I have to save user notification message with emoji in it. I done the whole database/table/column alter but I can not find anywhere the codes which i need to insert to show emoji on mobile phone when user reads the notification. Tnx

weleinew's avatar
weleinew
Best Answer
Level 1

character_set_client, _connection, and _results must all be utf8mb4 for that shortcake to be eatable.

Something, somewhere, is setting a subset of those individually. Rummage through my.cnf and phpmyadmin's settings -- something is not setting all three. Many apps using these emojis. If you jailbreak the device using RootlessJB, The process become much easier for the app integration.

If SET NAMES utf8mb4 is executed, all three set correctly.

The sun shone because it is only 3-bytes - E2 98 80; utf8 is sufficient for 3-byte utf8 encodings of Unicode characters.

Please or to participate in this conversation.