How to display emoji char in HTML

jason_luo picture jason_luo · May 14, 2012 · Viewed 39.5k times · Source

I saved the face "savouring delicious food emoji" to database, and read it in php json_encode which show "uD83D\uDE0B"。 but usually we use one <img /> label to replace it . however,usually I just find this format '\uE056' not "uD83D\uDE0B",to replace with pic E056.png .

I don't know how to get the pic accroding to 'uD83D\uDE0B'.someone know ?

What the relation between 'uD83D\uDE0B' and '\uE056', they both represent emoji "savouring delicious food"?

Answer

Jukka K. Korpela picture Jukka K. Korpela · May 14, 2012

The Unicode character U+1F60B FACE SAVOURING DELICIOUS FOOD is a so-called Plane 1 character, which means that its UTF-16 encoded form consists of two 16-bit code units, namely 0xD83D 0xDE0B. Generally, Plane 1 characters cause considerable problems because many programs are not prepared to deal with them, and few fonts contain them.

According to http://www.fileformat.info/info/unicode/char/1f60b/fontsupport.htm this particular character only exists in DejaVu fonts and in Symbola, but the versions of DejaVu I’m using don’t contain it.

Instead of dealing with the problems of encodings (which are not that difficult, but require extra information), you can use the character reference &#x1f608; in HTML. But this does not solve the font problem. I don’t know about iPhone fonts, but in general in web browsing, the odds of a computer having any font capable of rendering the character are probably less than 1%. So you may need to use downloadable fonts. Using an image is obviously much simpler and mostly more reliable.

U+E056 is a Private Use codepoint, which means that anybody can make an agreement about its meaning with his brother or with himself, without asking anyone else’s mind. A font designer may assign any glyph to it.