首页 > 开发 > PHP > 正文

php怎么取读xml文件

2024-05-04 21:58:41
字体:大 中 小
来源:转载
供稿:网友
  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. ?> 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表