这篇文章主要为大家详细介绍了PHP利用SimpleXML函数来加载和解析XML文档的简单示例,具有一定的参考价值,可以用来参考一下。
感兴趣的小伙伴,下面一起跟随四海网的小玲来看看吧!
大量SmipleXML函数可用来加载和解析大量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
/* 四海网 www.q1010.com */
$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."
}
}
}
本文来自:http://www.q1010.com/173/15513-0.html
注:关于PHP利用SimpleXML函数来加载和解析XML文档的简单示例的内容就先介绍到这里,更多相关文章的可以留意四海网的其他信息。
关键词:XML
四海网收集整理一些常用的php代码,JS代码,数据库mysql等技术文章。