欧美日韩不卡一区二区三区,www.蜜臀.com,高清国产一区二区三区四区五区,欧美日韩三级视频,欧美性综合,精品国产91久久久久久,99a精品视频在线观看

php語言

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

時間:2025-02-27 20:33:58 php語言 我要投稿
  • 相關推薦

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

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

php如何基于dom實現(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>

  運行結果如下:

  PHP Hacks - Jack Herrington - O'Reilly

  Podcasting Hacks - Jack Herrington - O'Reilly

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

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

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

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

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

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

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

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

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

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