PHP 中的 simpleXML 和重音字符
我编写了一个使用 ISO-8859-15 编码的 XML 文件,并且提要中的大部分数据都是通过 htmlspecialchars() 运行的.
I have written an XML file which is using the ISO-8859-15 encoding and most of the data within the feed is ran through htmlspecialchars().
然后我使用 simplexml_load_string() 来检索要在我的脚本中使用的 XML 文件的内容.但是,如果我有任何特殊字符(即:é á ó),它会显示为é á ó".
I am then using simplyxml_load_string() to retrieve the contents of the XML file to use in my script. However, if I have any special characters (ie: é á ó) it comes out as "é á ó". The
如何让我的脚本显示正确的特殊重音字符?
How can I get my script to display the proper special accented characters?
推荐答案
您输出的字符编码可能与实际编码的 XML 数据不同.
You’re probably using a different character encoding for you output than the XML data is actually encoded.
根据您的描述,您的 XML 数据使用 UTF-8 编码,但您的输出使用的是 ISO 8859-15.因为 UTF-8 将字符 é (U+00E9) 编码为 0xC3A9,并且在 ISO 8859 中分别表示两个字符 Ã 和 © -15.
According to your description, your XML data encoded with UTF-8 but your output is using ISO 8859-15. Because UTF-8 encodes the character é (U+00E9) with 0xC3A9 and that represents the two characters à and © respectively in ISO 8859-15.
因此,您也可以使用 UTF-8 作为输出.或者,您使用 mb_convert_encoding
将数据从 UTF-8 转换为 ISO 8859-15.
So you either use UTF-8 for your output as well. Or you convert the data from UTF-8 to ISO 8859-15 using mb_convert_encoding
.
相关文章