色尼玛亚洲综合影院,亚洲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文檔,轉載需保留來源!

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

主站蜘蛛池模板: 新龙县| 舞钢市| 和平县| 迁安市| 仪征市| 收藏| 乐安县| 开阳县| 温宿县| 扎囊县| 平塘县| 屏南县| 朝阳市| 冕宁县| 巴林左旗| 萝北县| 肃南| 浠水县| 长武县| 宿松县| 竹北市| 永新县| 宜章县| 临泽县| 沙雅县| 科技| 沙雅县| 罗源县| 法库县| 通州市| 凉城县| 盘山县| 天等县| 邵阳县| 邹平县| 萨嘎县| 武乡县| 桂东县| 板桥市| 中卫市| 襄汾县|