如何在PHP中读取utf-8编码的XML文件?

时间:2015-05-25 10:00:42

标签: php xml utf-8

代码工作正常&从XML文件中获取值并生成这些值的形式。我将encoding =“UTF-8”添加到XML标记。它正在发出以下警告和错误。 谢谢你

Warning: DOMDocument::load(): parsing XML declaration: '?>' expected in file:///C:/xampp/htdocs/Urdu/english.xml, line: 1 in C:\

Warning: simplexml_load_file(): english.xml:1: parser error : parsing XML declaration: '?>' expected in C:\

Warning: simplexml_load_file(): <?xml version="1.0" standalone="yes" encoding="UTF-8"?> in C:\xampp\htdocs\Urdu\getxmlform.php on line 64

Warning: simplexml_load_file(): ^ in C:\xampp\htdocs\Urdu\getxmlform.php on line 64

Catchable fatal error: Argument 1 passed to makeNodeField() must be an instance of SimpleXMLElement, boolean given, called in C:\ on line 66 and defined in C:\

1 个答案:

答案 0 :(得分:1)

您的XML声明行无效:

<?xml version="1.0" standalone="yes" encoding="UTF-8"?>
                   ^^^^^^^^^^^^^^^^^

将带下划线的部分移到后面,它将正确解析:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>