simplexml_load_file()函数
2014-08-25 15:19
369 查看
定义和用法
simplexml_load_file() 函数把 XML 文档载入对象中。
如果失败,则返回 false。
语法
simplexml_load_file(file,class,options,ns,is_prefix)
参数 描述
file 必需。规定要使用的 XML 文档。
class 可选。规定新对象的 class。
options 可选。规定附加的 Libxml 参数。
ns 可选。
is_prefix 可选。
返回值
返回类 SimpleXMLElement 的一个对象,该对象的属性包含 XML 文档中的数据。如果失败,则返回 false。
例子
XML 文件:
<?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 代码:
<?php
if (file_exists('test.xml'))
{
$xml = simplexml_load_file('test.xml');
var_dump($xml);
}
else
{
exit('Error.');
}
?>
输出:
object(SimpleXMLElement)#1 (4)
{
["to"]=> string(4) "George"
["from"]=> string(4) "John"
["heading"]=> string(8) "Reminder"
["body"]=> string(29) "Don't forget the meeting!"
}
simplexml_load_file() 函数把 XML 文档载入对象中。
如果失败,则返回 false。
语法
simplexml_load_file(file,class,options,ns,is_prefix)
参数 描述
file 必需。规定要使用的 XML 文档。
class 可选。规定新对象的 class。
options 可选。规定附加的 Libxml 参数。
ns 可选。
is_prefix 可选。
返回值
返回类 SimpleXMLElement 的一个对象,该对象的属性包含 XML 文档中的数据。如果失败,则返回 false。
例子
XML 文件:
<?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 代码:
<?php
if (file_exists('test.xml'))
{
$xml = simplexml_load_file('test.xml');
var_dump($xml);
}
else
{
exit('Error.');
}
?>
输出:
object(SimpleXMLElement)#1 (4)
{
["to"]=> string(4) "George"
["from"]=> string(4) "John"
["heading"]=> string(8) "Reminder"
["body"]=> string(29) "Don't forget the meeting!"
}
相关文章推荐
- php中simplexml_load_file函数的学习
- simplexml_load_file()将xml转化为php对象的函数
- php中simplexml_load_file()函数用法详细
- 在使用simplexml_load_file()函数读取xml文件时遇到<![CDATA[]]>,怎么让其进行解析
- php中simplexml_load_file函数用法实例
- php中simplexml_load_file函数用法实例
- php中simplexml_load_file函数用法实例
- 当file_get_contents 或者 simplexml_load_file的时候乱码
- RichTextBox的LoadFile函数的用法
- [导入]ASP常用函数:LoadFromFile()
- 【 IDA】使用IDA load file功能,导入JNI.h解析【JNI 函数】
- 【 IDA】使用IDA load file功能,导入JNI.h解析【JNI 函数】
- php使用simplexml_load_file加载XML文件并显示XML的方法
- 当file_get_contents或者simplexml_load_file的时候乱码
- 针对MYSQL数据注入时用到的 load_file()函数
- simplexml_load_file()php解析xml文档
- 当file_get_contents或者simplexml_load_file的时候乱码
- MYSQL注入中load_file()函数的进一步应用
- PHP中Simplexml_Load_file解析xml实例
- MYSQL注入中load_file()函数的进一步应用