-2

I converted a forum MySQL database to utf8mb4. Seems to be working fine as Emojis are saving and displaying fine.

But I am having issues with a chatbox. emojis are saved in the database as Unicode "%uD83D%uDE0B"

Works fine if emojis is inserted by phpmyadmin.

Can this be solved by mb_convert or something ?

php 5.6

Could this be the problematic code-

$str = unhtmlspecialchars(str_replace(array("\n"), '', trim(convert_urlencoded_unicode($str))));

With code ☀️ 3 byte emoji works, do not. with code commented // hex for both.

Arsh Dhillon
  • 101
  • 1
  • 9

1 Answers1

0

Do not touch UTF-16. Use only UTF-8. In MySQL, UTF-8 is CHARACTER SET utf8mb4.

is hex D83DDE0B in UTF-16, but you need hex F09F988B in utf8mb4.

Perhaps the data is being created by Java or some other source?

There is virtually no reason to every us a conversion routine in PHP.

Rick James
  • 135,179
  • 13
  • 127
  • 222
  • DB is utf8mb4 with collation utf8mb4_unicode_520_ci, its php and MySql only. I have update the question. – Arsh Dhillon Jan 11 '18 at 15:05
  • Do not use any conversion routines in PHP -- they are likely to make things _worse_. Provide the bin2hex() before and after your `$str=` code. – Rick James Jan 11 '18 at 15:23