PHP透过DOM方式解析获得每本书的作者和书名
程序员文章站
2024-04-03 21:47:58
...
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);
?>
$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);
?>
相关文章
相关视频
上一篇: php多条件外加查询
下一篇: svn checkedout,该怎么处理