Wednesday 19 September 2012

iPhone emoji issues on MySQL + PHP

Today I had some troubles while storing text from iPhone device to MySQL.
I did some digging and found that the iPhone's emoji is suspicious.

PHP threw some error with byte characters in it.
After some time googling around,
found that the iphone emojis are mostly 4 bytes character,
and MySQL will only able to store the data if its in UTF84mb format.

What a tragedy.
There are 2 cures for this issue.

1. Upgrade your MySQL server and set the character to UTF84mb.
2. Remove the 4 byte character.

$cleanStrings = preg_replace('/[\xF0-\xF7][\x80-\xBF][\x80-\xBF][\x80-\xBF]/', '', $fourByteString);

Referred: http://kohkimakimoto.hatenablog.com/entry/2012/02/04/103457

Sigh, I hate emojis.