<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/wddx.examples.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'zh',
  ),
  'this' => 
  array (
    0 => 'wddx.examples-serialize.php',
    1 => 'wddx examples',
    2 => 'wddx examples',
  ),
  'up' => 
  array (
    0 => 'wddx.examples.php',
    1 => '示例',
  ),
  'prev' => 
  array (
    0 => 'wddx.examples.php',
    1 => '示例',
  ),
  'next' => 
  array (
    0 => 'ref.wddx.php',
    1 => 'WDDX 函数',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/wddx/examples.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="wddx.examples-serialize" class="section">
  <h2 class="title">wddx examples</h2>
  <p class="para">
   All the functions that serialize variables use the first
   element of an array to determine whether the array is to be
   serialized into an array or structure. If the first element has
   string key, then it is serialized into a structure, otherwise,
   into an array.
  </p>
  
  <div class="example" id="example-1">
   <p><strong>示例 #1 Serializing a single value with WDDX</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: #007700">echo </span><span style="color: #0000BB">wddx_serialize_value</span><span style="color: #007700">(</span><span style="color: #DD0000">"PHP to WDDX packet example"</span><span style="color: #007700">, </span><span style="color: #DD0000">"PHP packet"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   <div class="example-contents"><p>
    This example will produce:
   </p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
&lt;wddxPacket version=&#039;1.0&#039;&gt;&lt;header comment=&#039;PHP packet&#039;/&gt;&lt;data&gt;
&lt;string&gt;PHP to WDDX packet example&lt;/string&gt;&lt;/data&gt;&lt;/wddxPacket&gt;
</pre></div>
   </div>
  </div>

  <div class="example" id="example-2">
   <p><strong>示例 #2 Using incremental packets with WDDX</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$pi </span><span style="color: #007700">= </span><span style="color: #0000BB">3.1415926</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$packet_id </span><span style="color: #007700">= </span><span style="color: #0000BB">wddx_packet_start</span><span style="color: #007700">(</span><span style="color: #DD0000">"PHP"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">wddx_add_vars</span><span style="color: #007700">(</span><span style="color: #0000BB">$packet_id</span><span style="color: #007700">, </span><span style="color: #DD0000">"pi"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/* Suppose $cities came from database */<br /></span><span style="color: #0000BB">$cities </span><span style="color: #007700">= array(</span><span style="color: #DD0000">"Austin"</span><span style="color: #007700">, </span><span style="color: #DD0000">"Novato"</span><span style="color: #007700">, </span><span style="color: #DD0000">"Seattle"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">wddx_add_vars</span><span style="color: #007700">(</span><span style="color: #0000BB">$packet_id</span><span style="color: #007700">, </span><span style="color: #DD0000">"cities"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$packet </span><span style="color: #007700">= </span><span style="color: #0000BB">wddx_packet_end</span><span style="color: #007700">(</span><span style="color: #0000BB">$packet_id</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">$packet</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   <div class="example-contents"><p>
    This example will produce:
   </p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
&lt;wddxPacket version=&#039;1.0&#039;&gt;&lt;header comment=&#039;PHP&#039;/&gt;&lt;data&gt;&lt;struct&gt;
&lt;var name=&#039;pi&#039;&gt;&lt;number&gt;3.1415926&lt;/number&gt;&lt;/var&gt;&lt;var name=&#039;cities&#039;&gt;
&lt;array length=&#039;3&#039;&gt;&lt;string&gt;Austin&lt;/string&gt;&lt;string&gt;Novato&lt;/string&gt;
&lt;string&gt;Seattle&lt;/string&gt;&lt;/array&gt;&lt;/var&gt;&lt;/struct&gt;&lt;/data&gt;&lt;/wddxPacket&gt;
</pre></div>
   </div>
  </div>

  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    Strings should be encoded in UTF-8; to handle other encodings, convert
    the string first using <span class="function"><a href="function.mb-convert-encoding.php" class="function">mb_convert_encoding()</a></span>,
    <span class="methodname"><a href="uconverter.transcode.php" class="methodname">UConverter::transcode()</a></span>, or <span class="function"><a href="function.iconv.php" class="function">iconv()</a></span>.
   </p>
  </p></blockquote>
 </div><?php manual_footer($setup); ?>