PHP中的simpleXML和重音字符 [英] simpleXML and accented characters in PHP
问题描述
我已经编写了一个使用ISO-8859-15编码的XML文件,并且Feed中的大多数数据都是通过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().
I然后使用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用0xC3A9编码字符é(U + 00E9),并且在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
。
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
.
这篇关于PHP中的simpleXML和重音字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!