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

php怎么取读xml文件

WBOY
WBOY原创
2016-05-25 16:41:461102浏览

<?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