Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > f800694edefe91adea2624f711a41a2d > files > 13025

php-manual-en-5.5.7-1.mga4.noarch.rpm

<!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 callbacks</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="yaml.callbacks.html">Callbacks</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="yaml.callbacks.emit.html">Emit callbacks</a></div>
 <div class="up"><a href="yaml.callbacks.html">Callbacks</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="yaml.callbacks.parse" class="section">
  <h2 class="title">Parse callbacks</h2>
  <p class="para">
   Parse <span class="type"><span class="type callbacks">callbacks</span></span> are invoked by
    <span class="function"><a href="function.yaml-parse.html" class="function">yaml_parse()</a></span>,  <span class="function"><a href="function.yaml-parse-file.html" class="function">yaml_parse_file()</a></span> or
    <span class="function"><a href="function.yaml-parse-url.html" 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-4099">
   <p><strong>Example #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 />&nbsp;*&nbsp;Parsing&nbsp;callback&nbsp;for&nbsp;yaml&nbsp;tag.<br />&nbsp;*&nbsp;@param&nbsp;mixed&nbsp;$value&nbsp;Data&nbsp;from&nbsp;yaml&nbsp;file<br />&nbsp;*&nbsp;@param&nbsp;string&nbsp;$tag&nbsp;Tag&nbsp;that&nbsp;triggered&nbsp;callback<br />&nbsp;*&nbsp;@param&nbsp;int&nbsp;$flags&nbsp;Scalar&nbsp;entity&nbsp;style&nbsp;(see&nbsp;YAML_*_SCALAR_STYLE)<br />&nbsp;*&nbsp;@return&nbsp;mixed&nbsp;Value&nbsp;that&nbsp;YAML&nbsp;parser&nbsp;should&nbsp;emit&nbsp;for&nbsp;the&nbsp;given&nbsp;value<br />&nbsp;*/<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">tag_callback&nbsp;</span><span style="color: #007700">(</span><span style="color: #0000BB">$value</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$tag</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$flags</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;</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">());&nbsp;</span><span style="color: #FF8000">//&nbsp;debugging<br />&nbsp;&nbsp;</span><span style="color: #007700">return&nbsp;</span><span style="color: #DD0000">"Hello&nbsp;</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&nbsp;</span><span style="color: #007700">=&nbsp;&lt;&lt;&lt;YAML<br /></span><span style="color: #DD0000">greeting:&nbsp;!example/hello&nbsp;World<br /></span><span style="color: #007700">YAML;<br /><br /></span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">yaml_parse</span><span style="color: #007700">(</span><span style="color: #0000BB">$yaml</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$ndocs</span><span style="color: #007700">,&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'!example/hello'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'tag_callback'</span><span style="color: #007700">,<br />&nbsp;&nbsp;));<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>The above example will output
something similar to:</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><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="yaml.callbacks.html">Callbacks</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="yaml.callbacks.emit.html">Emit callbacks</a></div>
 <div class="up"><a href="yaml.callbacks.html">Callbacks</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>