Home  >  Article  >  php教程  >  php怎么取读xml文件

php怎么取读xml文件

WBOY
WBOYOriginal
2016-05-25 16:41:461060browse

<?php
$doc = new DOMDocument();
$doc->load(&#39;books.xml&#39;);
$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 - $publishern";
}
?>


本文链接:

收藏随意^^请保留教程地址.

Statement:
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