simpleXML and accented characters in PHP

自古美人都是妖i 提交于 2019-12-02 04:20:24

问题


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 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?


回答1:


You’re probably using a different character encoding for you output than the XML data is actually encoded.

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.

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.



来源:https://stackoverflow.com/questions/1571626/simplexml-and-accented-characters-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!