首頁 >php教程 >php手册 >php怎么取读xml文件

php怎么取读xml文件

WBOY
WBOY原創
2016-05-25 16:41:461103瀏覽

<?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";
}
?>


本文链接:

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

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn