PHP Utf8解码问题 [英] PHP Utf8 Decoding Issue
问题描述
我有以下地址行: Praha 5,StaréMěsto,
我需要先对该字符串使用utf8_decode()函数,然后才能将其写入PDF文件(使用domPDF lib).
但是,上述地址行的php utf8解码功能似乎不正确(或者不完整).
以下代码:
<?php echo utf8_decode('Praha 5, Staré Město,'); ?>
产生这个:
Praha 5,StaréM?sto,
知道为什么ě没有得到解码吗?
utf8_decode
将字符串从UTF-8编码转换为ISO-8859-1(又称拉丁1").
Latin-1编码不能代表字母ě".就这么简单.
解码"是一个总称,它与iconv('UTF-8', 'ISO-8859-1', $string)
相同.
请参见每个程序员绝对肯定要了解与文本配合使用的编码和字符集的内容. /p>
I have the following address line: Praha 5, Staré Město,
I need to use utf8_decode() function on this string before I can write it to a PDF file (using domPDF lib).
However, the php utf8 decode function for the above address line appears incorrect (or rather, incomplete).
The following code:
<?php echo utf8_decode('Praha 5, Staré Město,'); ?>
Produces this:
Praha 5, Staré M?sto,
Any idea why ě is not getting decoded?
utf8_decode
converts the string from a UTF-8 encoding to ISO-8859-1, a.k.a. "Latin-1".
The Latin-1 encoding cannot represent the letter "ě". It's that simple.
"Decode" is a total misnomer, it does the same as iconv('UTF-8', 'ISO-8859-1', $string)
.
这篇关于PHP Utf8解码问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!