mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-18 05:26:57 +08:00
228 lines
9.2 KiB
HTML
228 lines
9.2 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>Parse a YAML stream</title>
|
|
</head>
|
|
<body class="docs"><div id="layout">
|
|
<div id="layout-content"><div id="function.yaml-parse" class="refentry">
|
|
<div class="refnamediv">
|
|
<h1 class="refname">yaml_parse</h1>
|
|
<p class="verinfo">(PECL yaml >= 0.4.0)</p><p class="refpurpose"><span class="refname">yaml_parse</span> — <span class="dc-title">Parse a YAML stream</span></p>
|
|
|
|
</div>
|
|
|
|
<div class="refsect1 description" id="refsect1-function.yaml-parse-description">
|
|
<h3 class="title">说明</h3>
|
|
<div class="methodsynopsis dc-description">
|
|
<span class="methodname"><strong>yaml_parse</strong></span>
|
|
( <span class="methodparam"><span class="type">string</span> <code class="parameter">$input</code></span>
|
|
[, <span class="methodparam"><span class="type">int</span> <code class="parameter">$pos</code><span class="initializer"> = 0</span></span>
|
|
[, <span class="methodparam"><span class="type">int</span> <code class="parameter reference">&$ndocs</code></span>
|
|
[, <span class="methodparam"><span class="type">array</span> <code class="parameter">$callbacks</code><span class="initializer"> = <strong><code>NULL</code></strong></span></span>
|
|
]]] ) : <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span></div>
|
|
|
|
<p class="para rdfs-comment">
|
|
Convert all or part of a YAML document stream to a PHP variable.
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 parameters" id="refsect1-function.yaml-parse-parameters">
|
|
<h3 class="title">参数</h3>
|
|
<p class="para">
|
|
<dl>
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">input</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
The <span class="type"><a href="language.types.string.html" class="type string">string</a></span> to parse as a YAML document stream.
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">pos</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
Document to extract from stream (<em>-1</em> for all
|
|
documents, <em>0</em> for first document, ...).
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">ndocs</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
If <code class="parameter">ndocs</code> is provided, then it is filled with the
|
|
number of documents found in stream.
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">callbacks</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
Content handlers for YAML nodes. Associative <span class="type"><a href="language.types.array.html" class="type array">array</a></span> of YAML
|
|
tag => <span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> mappings. See
|
|
<a href="yaml.callbacks.parse.html" class="link">parse callbacks</a> for more
|
|
details.
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
</dl>
|
|
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 returnvalues" id="refsect1-function.yaml-parse-returnvalues">
|
|
<h3 class="title">返回值</h3>
|
|
<p class="para">
|
|
Returns the value encoded in <code class="parameter">input</code> in appropriate
|
|
PHP type 或者在失败时返回 <strong><code>FALSE</code></strong>. If <code class="parameter">pos</code> is <em>-1</em> an
|
|
<span class="type"><a href="language.types.array.html" class="type array">array</a></span> will be returned with one entry for each document found
|
|
in the stream.
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 examples" id="refsect1-function.yaml-parse-examples">
|
|
<h3 class="title">范例</h3>
|
|
<p class="para">
|
|
<div class="example" id="example-4904">
|
|
<p><strong>Example #1 <span class="function"><strong>yaml_parse()</strong></span> example</strong></p>
|
|
<div class="example-contents">
|
|
<div class="phpcode"><pre><span style="color: #000000">
|
|
<span style="color: #0000BB"><?php<br />$yaml </span><span style="color: #007700">= <<<EOD<br /></span><span style="color: #DD0000">---<br />invoice: 34843<br />date: "2001-01-23"<br />bill-to: &id001<br /> given: Chris<br /> family: Dumars<br /> address:<br /> lines: |-<br /> 458 Walkman Dr.<br /> Suite #292<br /> city: Royal Oak<br /> state: MI<br /> postal: 48046<br />ship-to: *id001<br />product:<br />- sku: BL394D<br /> quantity: 4<br /> description: Basketball<br /> price: 450<br />- sku: BL4438H<br /> quantity: 1<br /> description: Super Hoop<br /> price: 2392<br />tax: 251.420000<br />total: 4443.520000<br />comments: Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.<br />...<br /></span><span style="color: #007700">EOD;<br /><br /></span><span style="color: #0000BB">$parsed </span><span style="color: #007700">= </span><span style="color: #0000BB">yaml_parse</span><span style="color: #007700">(</span><span style="color: #0000BB">$yaml</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$parsed</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span>
|
|
</span>
|
|
</pre></div>
|
|
</div>
|
|
|
|
<div class="example-contents"><p>以上例程的输出类似于:</p></div>
|
|
<div class="example-contents screen">
|
|
<div class="cdata"><pre>
|
|
array(8) {
|
|
["invoice"]=>
|
|
int(34843)
|
|
["date"]=>
|
|
string(10) "2001-01-23"
|
|
["bill-to"]=>
|
|
&array(3) {
|
|
["given"]=>
|
|
string(5) "Chris"
|
|
["family"]=>
|
|
string(6) "Dumars"
|
|
["address"]=>
|
|
array(4) {
|
|
["lines"]=>
|
|
string(34) "458 Walkman Dr.
|
|
Suite #292"
|
|
["city"]=>
|
|
string(9) "Royal Oak"
|
|
["state"]=>
|
|
string(2) "MI"
|
|
["postal"]=>
|
|
int(48046)
|
|
}
|
|
}
|
|
["ship-to"]=>
|
|
&array(3) {
|
|
["given"]=>
|
|
string(5) "Chris"
|
|
["family"]=>
|
|
string(6) "Dumars"
|
|
["address"]=>
|
|
array(4) {
|
|
["lines"]=>
|
|
string(34) "458 Walkman Dr.
|
|
Suite #292"
|
|
["city"]=>
|
|
string(9) "Royal Oak"
|
|
["state"]=>
|
|
string(2) "MI"
|
|
["postal"]=>
|
|
int(48046)
|
|
}
|
|
}
|
|
["product"]=>
|
|
array(2) {
|
|
[0]=>
|
|
array(4) {
|
|
["sku"]=>
|
|
string(6) "BL394D"
|
|
["quantity"]=>
|
|
int(4)
|
|
["description"]=>
|
|
string(10) "Basketball"
|
|
["price"]=>
|
|
int(450)
|
|
}
|
|
[1]=>
|
|
array(4) {
|
|
["sku"]=>
|
|
string(7) "BL4438H"
|
|
["quantity"]=>
|
|
int(1)
|
|
["description"]=>
|
|
string(10) "Super Hoop"
|
|
["price"]=>
|
|
int(2392)
|
|
}
|
|
}
|
|
["tax"]=>
|
|
float(251.42)
|
|
["total"]=>
|
|
float(4443.52)
|
|
["comments"]=>
|
|
string(68) "Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338."
|
|
}
|
|
</pre></div>
|
|
</div>
|
|
</div>
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 notes" id="refsect1-function.yaml-parse-notes">
|
|
<h3 class="title">注释</h3>
|
|
<div class="warning"><strong class="warning">Warning</strong>
|
|
<p class="para">
|
|
Processing untrusted user input with <span class="function"><strong>yaml_parse()</strong></span>
|
|
is dangerous if the use of <span class="function"><a href="unserialize.html" class="function">unserialize()</a></span> is enabled for
|
|
nodes using the <em>!php/object</em> tag. This behavior can be
|
|
disabled by using the <em>yaml.decode_php</em> ini setting.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 seealso" id="refsect1-function.yaml-parse-seealso">
|
|
<h3 class="title">参见</h3>
|
|
<p class="para">
|
|
<ul class="simplelist">
|
|
<li class="member"><span class="function"><a href="yaml_parse_file.html" class="function" rel="rdfs-seeAlso">yaml_parse_file()</a> - Parse a YAML stream from a file</span></li>
|
|
<li class="member"><span class="function"><a href="yaml_parse_url.html" class="function" rel="rdfs-seeAlso">yaml_parse_url()</a> - Parse a Yaml stream from a URL</span></li>
|
|
<li class="member"><span class="function"><a href="yaml_emit.html" class="function" rel="rdfs-seeAlso">yaml_emit()</a> - Returns the YAML representation of a value</span></li>
|
|
</ul>
|
|
</p>
|
|
</div>
|
|
|
|
|
|
</div></div></div></body></html> |