PHP透过DOM方式解析获得每本书的作者和书名

WBOY
Release: 2016-06-13 12:52:53
Original
1316 people have browsed it

PHP通过DOM方式解析获得每本书的作者和书名

  $doc = new DOMDocument('1.0','utf-8');
  $doc -> load('book.xml');
  $books = $doc ->getElementsByTagName('book');
  $first_book = $books ->item(0);
  $first_title = $first_book ->getElementByTagName('title')->item(0)->nodeValue;
  $first_author = $first_book ->getElementByTagName('author')->item(0)->nodeValue;
  $second_book = $books ->item(1);
  $second_title = $second_book ->getElementsByTagName('title');
  $tar = $title ->item(0);
  $text = $tar ->nodeValue;
  $third_book = $books ->item(2);
  $third_title = $third_book ->getElementsByTagName('title')->item(0)->nodeValue;
  $third_author = $third_book ->getElementsByTagName('author')->item(0)->nodeValue;
  var_dump($third_title);
  var_dump($third_author);
?>

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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template