I tried to store emoji to my database and it is save like this '😀ðŸ˜'. How can i displayed it as EMOJI on my PHP website. What should I do?
2 Answers
PHP is agnostic on this part. It only understands binary. The only responsible to display the emoji correctly is the web page itself.
To be more exact, the PHP stores strings as a series of bytes. Emoji are as big as 4 (or even more than 4) bytes. If you just see the binary data with the wrong encoding, then this artifact will appear. Instead make sure that your page has a proper unicode encoding , something like
<head>
<meta charset="UTF-8">
</head>
And also on the php side:
header('Content-type: text/plain; charset=utf-8');

- 1,792
- 23
- 32
-
But how can i dispaly 'ðŸ˜' as emoji to my browser? – Felix Kamote Sep 03 '17 at 08:24
-
I have a meta tag like that but it still display like Pussycat 👅👅👅 not as an Emoji – Felix Kamote Sep 03 '17 at 08:30
several possible issues,
1: if you're using MySQL and the utf8
character-set, you'll get these kinds of results, because MySQL does not handle this by default, and MySQL's UTF8
is not UTF8, it's a 3-byte subset of the real 4-byte utf8 which doesn't cover emojis, and MySQL calls the real utf8 for utf8mb4
, and furthermore, by default, MySQL truncates invalid 4-byte characters to some random garbage (this insane behavior can be avoided by turning on the STRICT_TRANS_TABLES
or TRADITIONAL
SQL_MODE, however) - however, retroactively changing from utf8 to utf8mb4 will not repair your existing corrupted data :(
2: you don't specify the character-set in the response headers, or worse, you specify the wrong character-set. unfortunately, if you're not specific on the character-set, browsers will assume you're using the ISO-8859-1
characterset.. make sure you give the header Content-Type: text/html; charset=utf-8
, explicitly specifying to the browser that your html is utf-8 encoded, and should be rendered as such.

- 46,049
- 7
- 62
- 106

- 19,904
- 4
- 43
- 89