栏目导航
热点推荐
- PHP技巧汇总:提高PHP性能的53个
- 关于PHP编程中session的问题集锦
- PHP之判断用户语言跳转网页
- 在PHP中养成7个面向对象的好习惯
- 基于PHP的cURL快速入门
- PHP100编程安全性小结
- PHP实例:PHP分页效果
- php精华:php模拟post行为代码总
- 完美解决PHP中文乱码问题
- PHP根据IP跳转不同城市代码
- 25个PHP游戏编程脚本代码
- PHP扩展curl和正则表达式轻松采
阅览排行
php生成xml文件
www.jz123.cn 2008-09-11 来源: 中国建站 编辑整理 我要投递新闻
php生成xml文件
<?php
$books = array();
$books [] = array(
'title' => 'PHP Hacks',
'author' => 'Jack Herrington',
'publisher' => "O'Reilly"
);
$books [] = array(
'title' => 'Podcasting Hacks',
'author' => 'Jack Herrington',
'publisher' => "O'Reilly"
);
$doc = new DOMDocument();
$doc->formatOutput = true;
$r = $doc->createElement( "books" );
$doc->appendChild( $r );
foreach( $books as $book )
{
$b = $doc->createElement( "book" );
$author = $doc->createElement( "author" );
$author->appendChild(
$doc->createTextNode( $book['author'] )
);
$b->appendChild( $author );
$title = $doc->createElement( "title" );
$title->appendChild(
$doc->createTextNode( $book['title'] )
);
$b->appendChild( $title );
$publisher = $doc->createElement( "publisher" );
$publisher->appendChild(
$doc->createTextNode( $book['publisher'] )
);
$b->appendChild( $publisher );
$r->appendChild( $b );
}
echo $doc->saveXML();
?>
上一篇:php读取xml 文件 下一篇:php file_get_contents函数