Problems with php xml characters

时间:2016-04-25 09:36:11

标签: php xml

Hello friends i have a problem with some characters reading a xml file from php i am using this source code:

$file = 'test.xml';
$xml_1 = simplexml_load_file($file);

echo ($xml_1->content);

its work ok but when the content is a special character like ñ ó it show a rarer character like this ñ i tried to include in html head utf8 charset but its the same

2 个答案:

答案 0 :(得分:0)

SimpleXML emits UTF-8 output by design. If you application does not support UTF-8 you'll have to convert with the usual tools (e.g. mb_convert_encoding()) but you need to take this into account:

  • You need to know for sure the encoding your app is using.
  • UTF-8 can hold the complete Unicode catalogue thus some characters may not have an equivalent in your target encoding.

Whatever, in 2016 there's no reason to use anything else than UTF-8 unless your maintaining legacy code.

答案 1 :(得分:0)

最后我找到了解决方案我必须使用utf8_decode php函数来转换字符串不能用于将utf8字符集放在头页中你必须先用php转换