<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/yaml.callbacks.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'zh',
  ),
  'this' => 
  array (
    0 => 'yaml.callbacks.parse.php',
    1 => 'Parse callbacks',
    2 => 'Parse callbacks',
  ),
  'up' => 
  array (
    0 => 'yaml.callbacks.php',
    1 => 'Callbacks',
  ),
  'prev' => 
  array (
    0 => 'yaml.callbacks.php',
    1 => 'Callbacks',
  ),
  'next' => 
  array (
    0 => 'yaml.callbacks.emit.php',
    1 => 'Emit callbacks',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/yaml/callbacks.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="yaml.callbacks.parse" class="section">
  <h2 class="title">Parse callbacks</h2>
  <p class="para">
   Parse <span class="type"><a href="language.types.callable.php" class="type callable">callable</a></span>s are invoked by
   <span class="function"><a href="function.yaml-parse.php" class="function">yaml_parse()</a></span>, <span class="function"><a href="function.yaml-parse-file.php" class="function">yaml_parse_file()</a></span> or
   <span class="function"><a href="function.yaml-parse-url.php" class="function">yaml_parse_url()</a></span> functions when a registered YAML tag is
   encountered. The callback is passed the tagged entity&#039;s value, the tag, and
   flags indicating the scalar entity style. The callback must return the data
   that the YAML parser should emit for this entity.
  </p>
  <div class="example" id="example-1">
   <p><strong>示例 #1 Parse callback example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/**<br /> * Parsing callback for yaml tag.<br /> * @param mixed $value Data from yaml file<br /> * @param string $tag Tag that triggered callback<br /> * @param int $flags Scalar entity style (see YAML_*_SCALAR_STYLE)<br /> * @return mixed Value that YAML parser should emit for the given value<br /> */<br /></span><span style="color: #007700">function </span><span style="color: #0000BB">tag_callback </span><span style="color: #007700">(</span><span style="color: #0000BB">$value</span><span style="color: #007700">, </span><span style="color: #0000BB">$tag</span><span style="color: #007700">, </span><span style="color: #0000BB">$flags</span><span style="color: #007700">) {<br />  </span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">func_get_args</span><span style="color: #007700">()); </span><span style="color: #FF8000">// debugging<br />  </span><span style="color: #007700">return </span><span style="color: #DD0000">"Hello </span><span style="color: #007700">{</span><span style="color: #0000BB">$value</span><span style="color: #007700">}</span><span style="color: #DD0000">"</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">$yaml </span><span style="color: #007700">= &lt;&lt;&lt;YAML<br /></span><span style="color: #DD0000">greeting: !example/hello World<br /></span><span style="color: #007700">YAML;<br /><br /></span><span style="color: #0000BB">$result </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">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">$ndocs</span><span style="color: #007700">, array(<br />    </span><span style="color: #DD0000">'!example/hello' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'tag_callback'</span><span style="color: #007700">,<br />  ));<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   <div class="example-contents"><p>以上示例的输出类似于：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
array(3) {
  [0]=&gt;
  string(5) &quot;World&quot;
  [1]=&gt;
  string(14) &quot;!example/hello&quot;
  [2]=&gt;
  int(1)
}
array(1) {
  [&quot;greeting&quot;]=&gt;
  string(11) &quot;Hello World&quot;
}
</pre></div>
   </div>
  </div>
 </div><?php manual_footer($setup); ?>