av手机免费在线观看,国产女人在线视频,国产xxxx免费,捆绑调教一二三区,97影院最新理论片,色之久久综合,国产精品日韩欧美一区二区三区

php語言

php如何基于dom實(shí)現(xiàn)圖書xml格式數(shù)據(jù)

時(shí)間:2025-02-27 20:33:58 php語言 我要投稿
  • 相關(guān)推薦

php如何基于dom實(shí)現(xiàn)圖書xml格式數(shù)據(jù)

  導(dǎo)語:php如何基于dom實(shí)現(xiàn)圖書xml格式數(shù)據(jù)呢?下面是小編給大家提供的代碼實(shí)現(xiàn)方法,大家可以參考閱讀,更多詳情請關(guān)注應(yīng)屆畢業(yè)生考試網(wǎng)。

php如何基于dom實(shí)現(xiàn)圖書xml格式數(shù)據(jù)

  <?php

  $doc = new DOMDocument();

  $doc->load( 'books.xml' );

  $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 - $publisher\n";

  }

  ?>

  books.xml文件如下:

  <?xml version="1.0"?>

  <books>

  <book>

  <author>Jack Herrington</author>

  <title>PHP Hacks</title>

  <publisher>O'Reilly</publisher>

  </book>

  <book>

  <author>Jack Herrington</author>

  <title>Podcasting Hacks</title>

  <publisher>O'Reilly</publisher>

  </book>

  </books>

  運(yùn)行結(jié)果如下:

  PHP Hacks - Jack Herrington - O'Reilly

  Podcasting Hacks - Jack Herrington - O'Reilly

【php如何基于dom實(shí)現(xiàn)圖書xml格式數(shù)據(jù)】相關(guān)文章:

php數(shù)組基于dom實(shí)現(xiàn)轉(zhuǎn)換xml格式數(shù)據(jù)03-06

PHP如何使用DOM和simplexml讀取xml文檔07-22

PHP如何使用curl實(shí)現(xiàn)數(shù)據(jù)抓取02-05

如何在PHP導(dǎo)出excel格式數(shù)據(jù)04-21

如何實(shí)現(xiàn)PHP獲取表單數(shù)據(jù)與HTML嵌入PHP腳本01-16

PHP中多態(tài)如何實(shí)現(xiàn)05-06

php如何實(shí)現(xiàn)快速排序04-03

基于PHP+Ajax實(shí)現(xiàn)表單驗(yàn)證的詳解05-19

PHP基于CURL進(jìn)行POST數(shù)據(jù)上傳實(shí)例05-31