Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+8 votes
in Q2A Core by

Questions or answers that include an Emoji character (standard unicode) fail to save correctly.

Is this a known bug that is looking to be resolved?

For instance, a question that features an Emoji in it, will only save the text before the Emoji character. Text after it is lost on submission.

To reproduce:-

  • Use Safari or Firefox (Mac) or Internet Explorer 10 or latest Firefox (Windows 8)
  • Cannot use Chrome - it doesn't yet support Emoji
  • Ask a question that includes an Emoji character - can copy and paste the character from http://getemoji.com
  • Submit question. Only text before the Emoji character is saved.
Q2A version: 1.6.2
@gidgreen provided a thorough answer below but there are two approaches for offering emoji support: The full-fledged solution described in @gidgreen’s answer, and an alternative fallback adjustment that uses HTML entities for adding partial support.  More details about these approaches can be found by the end of this comment:

1 Answer

+6 votes

This is actually a problem occurring at the MySQL level, since the regular MySQL UTF-8 character set does not support 4-byte UTF-8 characters, of which Emoji are an example.

If you are using MySQL 5.5.3 or later, there's a character set called utf8mb4 which can be substituted for utf8, and which allows Emoji. In order to switch to this character set you need to:

  • Change the encodings in qa_db_connect(...) in qa-db.php from utf8 to utf8mb4 (two places).
  • Change the character set of columns qa_posts.content (for post content), qa_words.word (for indexing), qa_users.handle (for searching), qa_userprofile.content (for profile pages), qa_messages.content (for private message / wall posts) to utf8mb4.
  • Or if you're creating a new Q2A installation you can skip the previous step and just change utf8 to utf8mb4 in qa_db_create_table_sql(...) in qa-db-install.php before installing.

I'm not sure if it makes sense to include this in the Q2A core since the utf8mb4 character set is only supported since MySQL 5.5.3, and can take up more space in some cases.