simplexml_load_file() 函数把 XML 文档载入对象中。
如果失败,则返回 false。
</>code
- simplexml_load_file(file,class,options,ns,is_prefix)
参数 | 描述 |
---|---|
file | 必需。规定要使用的 XML 文档。 |
class | 可选。规定新对象的 class。 |
options | 可选。规定附加的 Libxml 参数。 |
ns | 可选。 |
is_prefix | 可选。 |
返回类 SimpleXMLElement 的一个对象,该对象的属性包含 XML 文档中的数据。如果失败,则返回 false。
XML 文件:
</>code
- <?xml version="1.0" encoding="ISO-8859-1"?>
- <note>
- <to>George</to>
- <from>John</from>
- <heading>Reminder</heading>
- <body>Don't forget the meeting!</body>
- </note>
PHP 代码:
</>code
- <?php
- if (file_exists('test.xml'))
- {
- $xml =
simplexml_load_file('test.xml')
;- var_dump($xml);
- }
- else
- {
- exit('Error.');
- }
- ?>
输出:
</>code
- object(SimpleXMLElement)#1 (4)
- {
- ["to"]=> string(4) "George"
- ["from"]=> string(4) "John"
- ["heading"]=> string(8) "Reminder"
- ["body"]=> string(29) "Don't forget the meeting!"
- }
如对本文有疑问,请提交到交流论坛,广大热心网友会为你解答!! 点击进入论坛
Powered by 365建站网 RSS地图 HTML地图
copyright © 2013-2024 版权所有 鄂ICP备17013400号