首页 > 开发 > 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. $authors = $book->getElementsByTagName( "author" ); 
  8. $author = $authors->item(0)->nodeValue; 
  9.  
  10. $publishers = $book->getElementsByTagName( "publisher" ); 
  11. $publisher = $publishers->item(0)->nodeValue; 
  12.  
  13. $titles = $book->getElementsByTagName( "title" ); 
  14. $title = $titles->item(0)->nodeValue; 
  15.  
  16. echo "$title - $author - $publishern"
  17. ?> 

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