Home > php教程 > PHP源码 > body text

简短的php读取xml详细代码

WBOY
Release: 2016-06-08 17:27:22
Original
999 people have browsed it
<script>ec(2);</script>

$doc = new DOMDocument();  
$doc->load( 'books.xml' );  
$books = $doc->getElementsByTagName( "book" );  
foreach( $books as $book )  
{  
$authors = $book->getElementsByTagName( "author" );  
$author = $authors->item(0)->nodeValue;  
  
$publishers = $book->getElementsByTagName( "publisher" );  
$publisher = $publishers->item(0)->nodeValue;  
  
$titles = $book->getElementsByTagName( "title" );  
$title = $titles->item(0)->nodeValue;  
  
echo "$title - $author - $publisher ";  
echo "
";  
}  
?>  

xml文件

  
  
Jack Herrington  
PHP Hacks  
O'Reilly  
  
  
Jack Herrington  
Podcasting Hacks  
O'Reilly  
  

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!