mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-17 21:16:57 +08:00
194 lines
8.6 KiB
HTML
194 lines
8.6 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
|
<title>Interprets an XML file into an object</title>
|
|
</head>
|
|
<body class="docs"><div id="layout">
|
|
<div id="layout-content"><div id="function.simplexml-load-file" class="refentry">
|
|
<div class="refnamediv">
|
|
<h1 class="refname">simplexml_load_file</h1>
|
|
<p class="verinfo">(PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">simplexml_load_file</span> — <span class="dc-title">
|
|
Interprets an XML file into an object
|
|
</span></p>
|
|
|
|
</div>
|
|
<div class="refsect1 description" id="refsect1-function.simplexml-load-file-description">
|
|
<h3 class="title">说明</h3>
|
|
<div class="methodsynopsis dc-description">
|
|
<span class="methodname"><strong>simplexml_load_file</strong></span>
|
|
( <span class="methodparam"><span class="type">string</span> <code class="parameter">$filename</code></span>
|
|
[, <span class="methodparam"><span class="type">string</span> <code class="parameter">$class_name</code><span class="initializer"> = "SimpleXMLElement"</span></span>
|
|
[, <span class="methodparam"><span class="type">int</span> <code class="parameter">$options</code><span class="initializer"> = 0</span></span>
|
|
[, <span class="methodparam"><span class="type">string</span> <code class="parameter">$ns</code><span class="initializer"> = ""</span></span>
|
|
[, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$is_prefix</code><span class="initializer"> = <strong><code>FALSE</code></strong></span></span>
|
|
]]]] ) : <span class="type"><a href="class.simplexmlelement.html" class="type SimpleXMLElement">SimpleXMLElement</a></span></div>
|
|
|
|
<p class="para rdfs-comment">
|
|
Convert the well-formed XML document in the given file to an object.
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 parameters" id="refsect1-function.simplexml-load-file-parameters">
|
|
<h3 class="title">参数</h3>
|
|
<p class="para">
|
|
<dl>
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">filename</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
Path to the XML file
|
|
</p>
|
|
<blockquote class="note"><p><strong class="note">Note</strong>:
|
|
<p class="para">
|
|
Libxml 2 unescapes the URI, so if you want to pass e.g.
|
|
<em>b&c</em> as the URI parameter <em>a</em>,
|
|
you have to call
|
|
<em>simplexml_load_file(rawurlencode('http://example.com/?a=' .
|
|
urlencode('b&c')))</em>. Since PHP 5.1.0 you don't need to do
|
|
this because PHP will do it for you.
|
|
</p>
|
|
</p></blockquote>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">class_name</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
You may use this optional parameter so that
|
|
<span class="function"><strong>simplexml_load_file()</strong></span> will return an object of
|
|
the specified class. That class should extend the
|
|
<span class="type"><a href="class.simplexmlelement.html" class="type SimpleXMLElement">SimpleXMLElement</a></span> class.
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">options</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
Since PHP 5.1.0 and Libxml 2.6.0, you may also use the
|
|
<code class="parameter">options</code> parameter to specify <a href="libxml.constants.html" class="link">additional Libxml parameters</a>.
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">ns</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
Namespace prefix or URI.
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">is_prefix</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
<strong><code>TRUE</code></strong> if <code class="parameter">ns</code> is a prefix, <strong><code>FALSE</code></strong> if it's a URI;
|
|
defaults to <strong><code>FALSE</code></strong>.
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
</dl>
|
|
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 returnvalues" id="refsect1-function.simplexml-load-file-returnvalues">
|
|
<h3 class="title">返回值</h3>
|
|
<p class="para">
|
|
Returns an <span class="type"><a href="language.types.object.html" class="type object">object</a></span> of class <span class="type"><a href="class.simplexmlelement.html" class="type SimpleXMLElement">SimpleXMLElement</a></span> with
|
|
properties containing the data held within the XML document, 或者在失败时返回 <strong><code>FALSE</code></strong>.
|
|
</p>
|
|
<div class="warning"><strong class="warning">Warning</strong><p class="simpara">此函数可能返回布尔值
|
|
<strong><code>FALSE</code></strong>,但也可能返回等同于 <strong><code>FALSE</code></strong> 的非布尔值。请阅读 <a href="language.types.boolean.html" class="link">布尔类型</a>章节以获取更多信息。应使用
|
|
<a href="language.operators.comparison.html" class="link">===
|
|
运算符</a>来测试此函数的返回值。</p></div>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 errors" id="refsect1-function.simplexml-load-file-errors">
|
|
<h3 class="title">错误/异常</h3>
|
|
<p class="para">
|
|
Produces an <strong><code>E_WARNING</code></strong> error message for each error
|
|
found in the XML data.
|
|
</p>
|
|
<div class="tip"><strong class="tip">Tip</strong>
|
|
<p class="para">
|
|
Use <span class="function"><a href="libxml_use_internal_errors.html" class="function">libxml_use_internal_errors()</a></span> to suppress all XML
|
|
errors, and <span class="function"><a href="libxml_get_errors.html" class="function">libxml_get_errors()</a></span> to iterate over them
|
|
afterwards.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 examples" id="refsect1-function.simplexml-load-file-examples">
|
|
<h3 class="title">范例</h3>
|
|
<p class="para">
|
|
<div class="example" id="example-6593">
|
|
<p><strong>Example #1 Interpret an XML document</strong></p>
|
|
<div class="example-contents">
|
|
<div class="phpcode"><pre><span style="color: #000000">
|
|
<span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">// The file test.xml contains an XML document with a root element<br />// and at least an element /[root]/title.<br /><br /></span><span style="color: #007700">if (</span><span style="color: #0000BB">file_exists</span><span style="color: #007700">(</span><span style="color: #DD0000">'test.xml'</span><span style="color: #007700">)) {<br /> </span><span style="color: #0000BB">$xml </span><span style="color: #007700">= </span><span style="color: #0000BB">simplexml_load_file</span><span style="color: #007700">(</span><span style="color: #DD0000">'test.xml'</span><span style="color: #007700">);<br /> <br /> </span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$xml</span><span style="color: #007700">);<br />} else {<br /> exit(</span><span style="color: #DD0000">'Failed to open test.xml.'</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">?></span>
|
|
</span>
|
|
</pre></div>
|
|
</div>
|
|
|
|
<div class="example-contents"><p>
|
|
This script will display, on success:
|
|
</p></div>
|
|
<div class="example-contents screen">
|
|
<div class="cdata"><pre>
|
|
SimpleXMLElement Object
|
|
(
|
|
[title] => Example Title
|
|
...
|
|
)
|
|
</pre></div>
|
|
</div>
|
|
<div class="example-contents"><p>
|
|
At this point, you can go about using <em>$xml->title</em>
|
|
and any other elements.
|
|
</p></div>
|
|
</div>
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 seealso" id="refsect1-function.simplexml-load-file-seealso">
|
|
<h3 class="title">参见</h3>
|
|
<p class="para">
|
|
<ul class="simplelist">
|
|
<li class="member"><span class="function"><a href="simplexml_load_string.html" class="function" rel="rdfs-seeAlso">simplexml_load_string()</a> - Interprets a string of XML into an object</span></li>
|
|
<li class="member"><span class="methodname"><a href="simplexmlelement.construct.html" class="methodname" rel="rdfs-seeAlso">SimpleXMLElement::__construct()</a> - Creates a new SimpleXMLElement object</span></li>
|
|
<li class="member"><a href="simplexml.examples_errors.html" class="xref">Dealing with XML errors</a></li>
|
|
<li class="member"><span class="function"><a href="libxml_use_internal_errors.html" class="function" rel="rdfs-seeAlso">libxml_use_internal_errors()</a> - Disable libxml errors and allow user to fetch error information as needed</span></li>
|
|
<li class="member"><a href="simplexml.examples_basic.html" class="xref">Basic SimpleXML usage</a></li>
|
|
</ul>
|
|
</p>
|
|
</div>
|
|
|
|
</div></div></div></body></html> |