源码 | 书库 | 模板 | 特效 | 广告 | 素材 | 工具 | 必备 | ALEXA | 字体
会员投稿 投稿指南 RSS订阅
您当前的位置是:主页>网络编程>PHP教程>

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函数

评论总数:2 [ 查看全部 ] 网友评论


关于我们隐私版权广告服务友情链接联系我们网站地图