当PHP无法指示正确的编码时如何加载XML? [英] How to load XML when PHP can't indicate the right encoding?

查看:243
本文介绍了当PHP无法指示正确的编码时如何加载XML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从远程位置加载XML源,因此我无法控制格式。不幸的是我试图加载的XML文件没有编码:

I'm trying to load an XML source from a remote location, so i have no control of the formatting. Unfortunately the XML file I'm trying to load has no encoding:

<ROOT xmlns:sql="urn:schemas-microsoft-com:xml-sql"> <NODE> </NODE> </ROOT>

当尝试类似:

$doc = new DOMDocument( );
$doc->load(URI);

我得到:

Input is not proper UTF-8, indicate encoding ! Bytes: 0xA3 0x38 0x2C 0x38

Ive考虑了抑制这种情况的方法,但没有运气。

Ive looked at ways to suppress this, but no luck. How should I load this so that I can use it with DOMDocument?

推荐答案

你可以编辑文档('pre-process it' ')来指定在添加XML声明时要传递的编码。这就是说,你必须确定自己,当然。然后DOM对象应该解析它。

You could edit the document ('pre-process it') to specify the encoding it is being delivered in adding an XML declaration. What that is, you'll have to ascertain yourself, of course. The DOM object should then parse it.

示例XML声明:

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

这篇关于当PHP无法指示正确的编码时如何加载XML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆