当前位置:首页 > PHP教程 > php应用 > 列表

php怎么取读xml文件

发布:smiling 来源: PHP粉丝网  添加日期:2014-08-21 10:00:20 浏览: 评论:0 
  1. <?php 
  2. $doc = new DOMDocument(); 
  3. $doc->load( 'books.xml' ); 
  4.  
  5. $books = $doc->getElementsByTagName( "book" ); 
  6. foreach( $books as $book ) 
  7. { 
  8. $authors = $book->getElementsByTagName( "author" ); 
  9. $author = $authors->item(0)->nodeValue; 
  10.  
  11. $publishers = $book->getElementsByTagName( "publisher" ); 
  12. $publisher = $publishers->item(0)->nodeValue; 
  13.  
  14. $titles = $book->getElementsByTagName( "title" ); 
  15. $title = $titles->item(0)->nodeValue; 
  16.  
  17. echo "$title - $author - $publishern"; 
  18. } 
  19. ?> 

Tags: php取读xml文件

分享到: