2

I'm attempting to display Emojis stored in my mysql database in the web browser and having issues. Initially the emoji's were being translated into

????

so did some research and have changed the charset of the desired table to utf8mb4. I am now able to store the unicodes in the database eg.

😴
💛

However when i retrieve the string via php that these are stored in, from the database i am only seeing the text around the codes and the codes themselves and not the emoji's. eg

"had a great weekend with the family 💛"

instead of:

"had a great weekend with the family 💛"

any suggestions what I'm doing wrong?

EDIT


Solved my issue. I was using

htmlspecialcahrs()

on the input of the strings I want to store. This was converting the

&

to

&amp

causing the Emoji's not to be recognised as

&amp#128564

is not valid. I just had to remove the

htmlspecialchars

re-insert the strings and it worked!

Thanks for looking

Lewis Thomas
  • 129
  • 11
  • You say that the database itself is utf8mb4 encoded, but what about the connection, file, PHP- and HTML-headers? – Qirel Feb 22 '16 at 21:59
  • I think you had it right the first time but browsers don't have every single unicode character stored in them. To display them you might need to find a font that does have them in and send that to the user over the website – EDD Feb 22 '16 at 22:01
  • i've changed the font and this has made no difference. the issue is with interpreting the output from the database so is there one specific area I should be looking at? – Lewis Thomas Feb 22 '16 at 22:10

2 Answers2

0

MySQL does not touch html entities such as 💛. Something else is generating them.

If you are using json in php, check for a second arg to avoid htmlentities.

If you are stuck with the entities, you can turn them back into characters via html_entity_decode().

It would be best to have utf8mb4 throughout; that is UNHEX('F09F929B') in the database, no use of html*() in PHP, etc.

Rick James
  • 135,179
  • 13
  • 127
  • 222
0

When I had a similar issue I found an unnecessary call to utf8_encode() that was affecting my PHP output. Removing this call resolved the issue.

Chris Beach
  • 4,302
  • 2
  • 31
  • 50