Home  >  Article  >  Backend Development  >  php输出xml必须header的解决方法_PHP

php输出xml必须header的解决方法_PHP

WBOY
WBOYOriginal
2016-05-31 19:29:14783browse

本文实例讲述了php输出xml必须header的解决方法。分享给大家供大家参考。具体方法如下:

问题描述:

最近在做一个xml输出时发现我们直接使用echo输入的xml文档会提示Error: Object # has no method ‘load'错误的了,后改用了header()输出xml头文件就解决了,下面记录一下。

解决方法:

由于xml长的和txt文件太相似,所以导致我总和txt混为一谈。

现来看看如下代码:

代码如下:

echo '

http://www.bitsCN.com/
2013-01-22T11:00:18+08:00

';
exit;


就是这么一段代码,死活输出的xml无法通过xml验证。
提示错误 Error: Object # has no method ‘load'
最后查了半天都和直接放在1.xml里的文件一样
具体代码如下

代码如下:



http://www.bitsCN.com/
2013-01-22T11:00:18+08:00


加个header就好了。 折腾了好几个小时。。。。。
具体代码如下

代码如下:

header("Content-type:text/xml");
echo '

http://www.bitsCN.com/
2013-01-22T11:00:18+08:00

';
exit;

希望本文所述对大家的php程序设计有所帮助。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn