simplexml_load_file Interprets an XML file into an object
发表日期:2021-07-01 08:57:25 | 来源: | | 浏览(972) 分类:SimpleXML 函数
simplexml_load_file
(PHP 5, PHP 7, PHP 8)
simplexml_load_file — Interprets an XML file into an object
说明
string
$filename
,string|null
$class_name
= SimpleXMLElement::class,int
$options
= 0,string
$namespace_or_prefix
= "",bool
$is_prefix
= false
): SimpleXMLElement|false
Convert the well-formed XML document in the given file to an object.
参数
-
filename
-
Path to the XML file
-
class_name
-
You may use this optional parameter so that simplexml_load_file() will return an object of the specified class. That class should extend the SimpleXMLElement class.
-
options
-
Since Libxml 2.6.0, you may also use the
options
parameter to specify additional Libxml parameters. -
namespace_or_prefix
-
Namespace prefix or URI.
-
is_prefix
-
true
ifnamespace_or_prefix
is a prefix,false
if it's a URI; defaults tofalse
.
返回值
Returns an object of class SimpleXMLElement with
properties containing the data held within the XML document, 或者在失败时返回 false
.
此函数可能返回布尔值
false
,但也可能返回等同于 false
的非布尔值。请阅读 布尔类型章节以获取更多信息。应使用
===
运算符来测试此函数的返回值。
错误/异常
Produces an E_WARNING
error message for each error
found in the XML data.
Use libxml_use_internal_errors() to suppress all XML errors, and libxml_get_errors() to iterate over them afterwards.
范例
示例 #1 Interpret an XML document
<?php // The file test.xml contains an XML document with a root element// and at least an element /[root]/title.if (file_exists('test.xml')) { $xml = simplexml_load_file('test.xml'); print_r($xml); } else { exit('Failed to open test.xml.'); } ?>
This script will display, on success:
SimpleXMLElement Object ( [title] => Example Title ... )
At this point, you can go about using $xml->title
and any other elements.
参见
- simplexml_load_string() - Interprets a string of XML into an object
- SimpleXMLElement::__construct() - Creates a new SimpleXMLElement object
- Dealing with XML errors
- libxml_use_internal_errors() - Disable libxml errors and allow user to fetch error information as needed
- Basic SimpleXML usage
- PHP(0)
- PHP杂项(34)
- PHP基础-李炎恢系列课程(20)
- 中文函数手册(0)
- 错误处理 函数(13)
- OPcache 函数(6)
- PHP 选项/信息 函数(54)
- Zip 函数(10)
- Hash 函数(15)
- OpenSSL 函数(63)
- Date/Time 函数(51)
- 目录函数(9)
- Fileinfo 函数(6)
- iconv 函数(11)
- 文件系统函数(81)
- 多字节字符串 函数(57)
- GD 和图像处理 函数(114)
- 可交换图像信息(5)
- Math 函数(50)
- 程序执行函数(11)
- PCNTL 函数(23)
- JSON 函数(4)
- SPL 函数(15)
- URL 函数(10)
- cURL 函数(32)
- 网络 函数(33)
- FTP 函数(36)
- Session 函数(23)
- PCRE 函数(11)
- PCRE 正则语法(19)
- 数组 函数(81)
- 类/对象 函数(18)
- 函数处理 函数(13)
- 变量处理 函数(37)
- SimpleXML 函数(3)
- simplexml_import_dom Get a SimpleXMLElement object from a DOM node(0)
- simplexml_load_file Interprets an XML file into an object(0)
- simplexml_load_string Interprets a string of XML into an object(0)
- 杂项 函数(31)
- 字符串 函数(101)