php生成xml文件
发布:smiling 来源: PHP粉丝网 添加日期:2014-08-21 10:02:50 浏览: 评论:0
- <?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"
- );
- //开源代码phpfensi.com
- $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();
- ?>
Tags: php生成xml文件
- 上一篇:php怎么取读xml文件
- 下一篇:php读取xml文件
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)