Afs35mm
Afs35mm

Reputation: 649

Why don't emojis render in my HTML and/or PHP?

In an effort to learn more about font rendering/encoding I'm more curious as to why when I copy and paste the emojis 😇🐵🙈 into a blank <html> page and simply save the .html file locally on my machine, or even start a local php server and serve files with the above emojis in there, they either show up as some weird characters (😇ðŸµðŸ™ˆ) or blank, respectively. Yet I know that when I type them straight into this very stack overflow ask textarea, they will render correctly in my browser, and be displayed as intended when viewing this page.

My understanding is that since mac osx now ships with the correct emoji fonts, they should be rendered as just that. So where is the disconnect between the HTML page you're looking at right now, and the local one I saved on my computer?

And recommended reading would be appreciated! :) errr.... 😀

Upvotes: 8

Views: 11685

Answers (1)

roeland
roeland

Reputation: 5761

When a web server sends a file to a browser, it will send a set of HTTP headers as well, relaying information about the content type, caching, etc. The content-type header also informs the browser which encoding was used:

Content-Type: text/html; charset=utf-8

If your open that file locally then your browser only gets the file and it has to guess the encoding. You can declare the encoding in the HTML head:

<meta charset="utf-8">

Upvotes: 24

Related Questions