ios 如何在 HTML 中显示表情符号字符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10580186/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 18:22:17  来源:igfitidea点击:

How to display emoji char in HTML

iphoneiosunicodeemojiemoticons

提问by jason_luo

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 .

我把“品尝美食emoji”的表情存到数据库中,在php json_encode中读取,显示“uD83D\uDE0B”。但通常我们用一个<img />标签来代替它。但是,通常我只是发现这种格式 '\uE056' 而不是“uD83D\uDE0B”,以替换为 pic E056.png 。

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

我不知道如何得到 'uD83D\uDE0B' 的图片。有人知道吗?

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

'uD83D\uDE0B'和'\uE056'是什么关系,都代表“品尝美食”的表情符号?

回答by Jukka K. Korpela

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.

Unicode字符U+1F60B FACE SAVORING DELICIOUS FOOD就是所谓的Plane 1字符,意思是它的UTF-16编码形式由两个16位的编码单元组成,即0xD83D 0xDE0B。一般来说,Plane 1 字符会引起相当大的问题,因为许多程序没有准备好处理它们,并且很少有字体包含它们。

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

根据http://www.fileformat.info/info/unicode/char/1f60b/fontsupport.htm这个特殊字符只存在于 DejaVu 字体和 Symbola 中,但我使用的 DejaVu 版本不包含它。

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.

您可以使用&#x1f608;HTML 中的字符引用,而不是处理编码问题(这并不难,但需要额外的信息)。但这并不能解决字体问题。我不了解 iPhone 字体,但一般来说,在网络浏览中,计算机拥有能够渲染字符的任何字体的几率可能不到 1%。所以你可能需要使用可下载的字体。使用图像显然要简单得多,而且大多更可靠。

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.

U+E056 是 Private Use 代码点,这意味着任何人都可以与他的兄弟或自己就其含义达成一致,而无需询问其他人的想法。字体设计者可以为其分配任何字形。

回答by Gideon Rosenthal

IMPORTANT: As of this posting, the only browser that doesn't automatically support emojis is chrome.

重要提示:截至本文发布时,唯一不自动支持表情符号的浏览器是 chrome。

FOR CHROME: Depending on what server side language you are using, you should be able to find a library that converts emojis for you. I recently needed to solve this issue with php and used this library:

FOR CHROME:根据您使用的服务器端语言,您应该能够找到一个可以为您转换表情符号的库。我最近需要用 php 解决这个问题并使用了这个库:

https://github.com/iamcal/php-emoji

https://github.com/iamcal/php-emoji

The creator essentially created a sprite and adjusts the css according to the unicode of the emoji. It isnt pretty, but luckily he/she did all the grunt work for you. If you're using a different language you should be able to find something similar.

创建者本质上创建了一个精灵,并根据表情符号的 unicode 调整了 css。它并不漂亮,但幸运的是他/她为你做了所有繁重的工作。如果您使用不同的语言,您应该能够找到类似的东西。

回答by MCKapur

how do I put those little boxes into a php file?

我如何将这些小盒子放入一个 php 文件中?

Same way as any other Unicode character. Just paste them and make sure you're saving the PHP file and serving the PHP page as UTF-8.

与任何其他 Unicode 字符的方式相同。只需粘贴它们并确保您正在保存 PHP 文件并将 PHP 页面作为 UTF-8 提供。

When I put it into a php file, it turns into question marks and what not

当我把它放入一个 php 文件时,它变成了问号,什么不是

Then you have an encoding problem. Work it out with Unicode characters you can actually see properly first, for example ?αд?日本, before worrying about the emoji.

那么你有一个编码问题。在担心表情符号之前,首先使用您实际上可以正确看到的 Unicode 字符来解决它,例如 ?αд?日本。

Your PHP file should be saved as UTF-8; the page it produces should be served as Content-Type: text/html;charset:UTF-8(or with similar meta tag); the MySQL database should be using a UTF-8 collation to store data and PHP should be talking to MySQL using UTF-8.

您的 PHP 文件应保存为 UTF-8;它产生的页面应作为Content-Type: text/html;charset:UTF-8(或具有类似的元标记);MySQL 数据库应该使用 UTF-8 排序规则来存储数据,PHP 应该使用 UTF-8 与 MySQL 对话。

However. Even handling everything correctly like this, PCs will still not show the emoji. That's because:

然而。即使像这样正确处理所有事情,PC 仍然不会显示表情符号。那是因为:

they don't have fonts that include shapes for those characters, and

他们没有包含这些字符形状的字体,并且

emoji are still completely unstandardised. Those characters you posted are in the Unicode Private Use Area, which means they don't have any official meaning at all.

表情符号仍然完全没有标准化。你张贴的那些字符在 Unicode 私人使用区,这意味着它们根本没有任何官方意义。

Each network in Japan uses different character codes for their emoji, mapped to different areas in the PUA. So even on another mobile phone, it probably won't display the correct character, unless you spend ages manually converting emoji codes for different networks. I'm guessing the ones you posted above are from SoftBank (iPhone?).

日本的每个网络为其表情符号使用不同的字符代码,映射到 PUA 中的不同区域。因此,即使在另一部手机上,它也可能无法显示正确的字符,除非您花费很长时间手动转换不同网络的表情符号代码。我猜你上面发布的那些来自 SoftBank(iPhone?)。

There is an ongoing proposal led by Google and Apple to collate the different networks' emoji and give them a proper standardised place in Unicode. Until then, getting emoji to display consistently across networks is an exercise in unhappiness. See the character overviewfrom the standardisation work to see how much converting you would have to do.

由 Google 和 Apple 牵头的一项正在进行的提案是整理不同网络的表情符号,并在 Unicode 中为它们提供适当的标准化位置。在那之前,让表情符号在网络上一致显示是一种不快乐的练习。请参阅标准化工作中的字符概览,了解您需要进行多少转换。

God, I hate emoji. All that pain for such a load of useless twee rubbish.

天啊,我讨厌表情符号。对于这么多无用的粗花呢垃圾来说,所有的痛苦。