search
Homephp教程php手册php输出xml必须header的解决方法,phpxmlheader

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

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

问题描述:

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

解决方法:

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

现来看看如下代码:

复制代码 代码如下:

echo '

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

';
exit;


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

复制代码 代码如下:



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


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

复制代码 代码如下:

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

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

';
exit;

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

php输出xml 类型为text/xml 怎进入xml模式

/*
写入xml文件
*/
mysql_connect('localhost','root','');
mysql_query("set names utf8");
mysql_select_db('1012javab');
$result = mysql_query("select * from goods");
while($a = mysql_fetch_assoc($result)){
$arr[] = $a;
}

// 实例化一个dom对象
$doc = new DOMDocument;
// 格式化输入
$doc->formatOutput = true;

// 创建一个根节点
$books = $doc->createElement('books');
// 添加元素节点
$books = $doc->appendChild($books);
/*
$books = $doc->appendChild($books);
$book = $doc->createElement('book');
$books->appendChild($book);
$title = $doc->createElement('ttt');
$book->appendChild($title);
*/
foreach($arr as $key=>$val){
echo 11;
$book = $doc->createElement('book');
foreach($val as $key1=>$val1){

###########################第一组
$title = $doc->createElement($key1);
// 创建一个文件节点
$content = $doc->createTextNode($val1);
$title->appendChild($content);
$book->appendChild($title);
}
$books->appendChild($book);
}

if($doc->save('goods.xml')){
echo 'yes';
}else{
echo 'no';
}

/*
$doc = new DOMDocument('1.0');
// we want a nice output
$doc->formatOutput = true;

$root = $doc->createElement('book');
$root = $doc->appendChild($root);

$title = $doc->createElement('title');
$title ......余下全文>>
 

php文件输出xml,ie中只显示value没有元素名称

正常现象,新版的浏览器都应该具备这自动解析的功能,这是w3c的标准。
自己查看源文件就好了。
 

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.