简体   繁体   English

PHP,HTML和字符编码

[英]PHP, HTML and character encodings

I actually have a fairly simple question but I'm unable to find an answer anywhere. 我实际上有一个非常简单的问题,但我无法在任何地方找到答案。 The PHP function html_entity_decode is supposed to "converts all HTML entities to their applicable characters from string ." PHP函数html_entity_decode应该“将所有HTML实体从string转换为适用的字符”。

So, since Ω 因此,由于Ω is the HTML encoding for the Greek captical letter Omega, I'd expect that echo html_entity_decode('Ω', ENT_COMPAT, 'UTF-8'); 是希腊首字母Omega的HTML编码,我希望echo html_entity_decode('Ω', ENT_COMPAT, 'UTF-8'); would output Ω. 将输出Ω。 But instaid, it outputs some strange characters which my browser can't recongize. 但是,它会立即输出一些我的浏览器无法识别的奇怪字符。 Why is this? 为什么是这样?

Thanks, 谢谢,

Martijn 马丁

When you convert entities into UTF-8 characters like your last parameter specifies, your output encoding must be UTF-8 as well. 当您将实体转换为最后一个参数指定的UTF-8字符时,您的输出编码也必须为UTF-8。 Otherwise, in a single-byte encoding like ISO-8859-1, you will see double-byte characters as two broken single ones. 否则,在像ISO-8859-1这样的单字节编码中,您将看到双字节字符是两个破损的单字符。

It's works fine: 很好用:

http://codepad.viper-7.com/tb2LaW http://codepad.viper-7.com/tb2LaW

Make sure your webpage encoding is UTF-8 确保您的网页编码为UTF-8

If you have different encoding on webpage change this: 如果您在网页上使用不同的编码,请更改以下内容:

html_entity_decode('Ω', ENT_COMPAT, 'UTF-8');
                                          ^^^^^

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM