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

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

主站蜘蛛池模板: 莱芜市| 铜鼓县| 泰和县| 塔河县| 新乐市| 陆丰市| 宜黄县| 汤原县| 河源市| 江山市| 韶关市| 汶上县| 上杭县| 延安市| 栖霞市| 汉中市| 临颍县| 大竹县| 太湖县| 胶州市| 洪江市| 彩票| 宝清县| 肇州县| 灌南县| 瓦房店市| 乃东县| 南木林县| 普格县| 荃湾区| 蓝田县| 蕲春县| 蒲江县| 荥阳市| 溧阳市| 蓝山县| 金阳县| 循化| 临沭县| 福贡县| 武乡县|