色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

探討如何使用SimpleXML函數來加載和解析XML文檔

大量SmipleXML函數可用來加載和解析大量XML文檔。
--------------------------------------------------------------------------------
1.simpleXML_load_file()函數來加載指定的XML文件到對象。如果加載文件時遇到問題,則返回FLASE。例:
book.xml文件:
復制代碼 代碼如下:
<?xml version="1.0" standalone="yes"?>
<library>
 <book>
  <title>Pride and Prejudice</title>
  <author gender="female">Jane Austen</author>
  <description>Jane Austen's most popular work.</description>
 </book>
 <book>
  <title>The Conformist</title>
  <author gender="male">Alberto Moravia</author>
  <description>Alberto Moravia's classic psyhcological novel.</description>
 </book>
 <book>
  <title>The Sun Also Rises</title>
  <author gender="male">Ernest Hemingway</author>
  <description>The masterpiece that launched Hemingway's career.</description>
 </book>
</library>

php文件:
復制代碼 代碼如下:
<?php
$xml=simplexml_load_file("book.xml");echo "<pre>";
var_dump($xml);
?>

輸出結果:
復制代碼 代碼如下:
object(SimpleXMLElement)#1 (1) {
  ["book"]=>
  array(3) {
    [0]=>
    object(SimpleXMLElement)#2 (3) {
      ["title"]=>
      string(19) "Pride and Prejudice"
      ["author"]=>
      string(11) "Jane Austen"
      ["description"]=>
      string(32) "Jane Austen's most popular work."
    }
    [1]=>
    object(SimpleXMLElement)#3 (3) {
      ["title"]=>
      string(14) "The Conformist"
      ["author"]=>
      string(15) "Alberto Moravia"
      ["description"]=>
      string(46) "Alberto Moravia's classic psyhcological novel."
    }
    [2]=>
    object(SimpleXMLElement)#4 (3) {
      ["title"]=>
      string(18) "The Sun Also Rises"
      ["author"]=>
      string(16) "Ernest Hemingway"
      ["description"]=>
      string(49) "The masterpiece that launched Hemingway's career."
    }
  }
}

php技術探討如何使用SimpleXML函數來加載和解析XML文檔,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 上杭县| 烟台市| 泰宁县| 河津市| 宁远县| 花莲市| 海林市| 辛集市| 宜黄县| 乌兰察布市| 于都县| 阜南县| 建瓯市| 大同县| 万安县| 托里县| 南阳市| 米脂县| 平潭县| 高州市| 八宿县| 措美县| 会泽县| 呼伦贝尔市| 玉溪市| 汝州市| 铜陵市| 云霄县| 洞头县| 任丘市| 廊坊市| 资阳市| 锦屏县| 张家川| 永城市| 汉源县| 环江| 都兰县| 阿尔山市| 甘肃省| 三河市|