<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >WDDX Functions</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REL="HOME" TITLE="PHP 手册" HREF="index.html"><LINK REL="UP" TITLE="函数参考" HREF="funcref.html"><LINK REL="PREVIOUS" TITLE="w32api_set_call_method" HREF="function.w32api-set-call-method.html"><LINK REL="NEXT" TITLE="wddx_add_vars" HREF="function.wddx-add-vars.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"></HEAD ><BODY CLASS="reference" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP 手册</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.w32api-set-call-method.html" ACCESSKEY="P" >上一页</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.wddx-add-vars.html" ACCESSKEY="N" >下一页</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="reference" ><A NAME="ref.wddx" ></A ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" >CLXXIV. WDDX Functions</H1 ><DIV CLASS="PARTINTRO" ><A NAME="AEN238224" ></A ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="wddx.intro" >简介</A ></H1 ><P > These functions are intended for work with <A HREF="http://www.openwddx.org/" TARGET="_top" >WDDX</A >. </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="wddx.requirements" >需求</A ></H1 ><P > In order to use WDDX, you will need to install the expat library (which comes with Apache 1.3.7 or higher). </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="wddx.installation" >安装</A ></H1 ><P > After installing expat compile PHP with <CODE CLASS="option" >--enable-wddx</CODE >. </P ><P > <TT CLASS="literal" >PHP</TT > 的 Windows 版本已经内置该扩展模块的支持。无需加载任何附加扩展库即可使用这些函数。</P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="wddx.configuration" >运行时配置</A ></H1 ><P >本扩展模块在 <TT CLASS="filename" >php.ini</TT > 中未定义任何配置选项。</P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="wddx.resources" >资源类型</A ></H1 ><P > This extension defines a WDDX packet identifier returned by <A HREF="function.wddx-packet-start.html" ><B CLASS="function" >wddx_packet_start()</B ></A >. </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="wddx.constants" >预定义常量</A ></H1 ><P >本扩展模块未定义任何常量。</P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="wddx.examples" >范例</A ></H1 ><P > 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 ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN238252" ></A ><P ><B >例 1. Serializing a single value with WDDX</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /></font><font color="#007700">echo </font><font color="#0000BB">wddx_serialize_value</font><font color="#007700">(</font><font color="#DD0000">"PHP to WDDX packet example"</font><font color="#007700">, </font><font color="#DD0000">"PHP packet"</font><font color="#007700">);<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ><P > This example will produce: </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" ><wddxPacket version='1.0'><header comment='PHP packet'/><data> <string>PHP to WDDX packet example</string></data></wddxPacket></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN238257" ></A ><P ><B >例 2. Using incremental packets with WDDX</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br />$pi </font><font color="#007700">= </font><font color="#0000BB">3.1415926</font><font color="#007700">;<br /></font><font color="#0000BB">$packet_id </font><font color="#007700">= </font><font color="#0000BB">wddx_packet_start</font><font color="#007700">(</font><font color="#DD0000">"PHP"</font><font color="#007700">);<br /></font><font color="#0000BB">wddx_add_vars</font><font color="#007700">(</font><font color="#0000BB">$packet_id</font><font color="#007700">, </font><font color="#DD0000">"pi"</font><font color="#007700">);<br /><br /></font><font color="#FF8000">/* Suppose $cities came from database */<br /></font><font color="#0000BB">$cities </font><font color="#007700">= array(</font><font color="#DD0000">"Austin"</font><font color="#007700">, </font><font color="#DD0000">"Novato"</font><font color="#007700">, </font><font color="#DD0000">"Seattle"</font><font color="#007700">);<br /></font><font color="#0000BB">wddx_add_vars</font><font color="#007700">(</font><font color="#0000BB">$packet_id</font><font color="#007700">, </font><font color="#DD0000">"cities"</font><font color="#007700">);<br /><br /></font><font color="#0000BB">$packet </font><font color="#007700">= </font><font color="#0000BB">wddx_packet_end</font><font color="#007700">(</font><font color="#0000BB">$packet_id</font><font color="#007700">);<br />echo </font><font color="#0000BB">$packet</font><font color="#007700">;<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ><P > This example will produce: </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" ><wddxPacket version='1.0'><header comment='PHP'/><data><struct> <var name='pi'><number>3.1415926</number></var><var name='cities'> <array length='3'><string>Austin</string><string>Novato</string> <string>Seattle</string></array></var></struct></data></wddxPacket></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >注意: </B > If you want to serialize non-ASCII characters you have to convert your data to UTF-8 first (see <A HREF="function.utf8-encode.html" ><B CLASS="function" >utf8_encode()</B ></A > and <A HREF="function.iconv.html" ><B CLASS="function" >iconv()</B ></A >). </P ></BLOCKQUOTE ></DIV ></DIV ></DIV ><DIV CLASS="TOC" ><DL ><DT ><B >目录</B ></DT ><DT ><A HREF="function.wddx-add-vars.html" >wddx_add_vars</A > -- Add variables to a WDDX packet with the specified ID</DT ><DT ><A HREF="function.wddx-deserialize.html" >wddx_deserialize</A > -- 别名 <A HREF="function.wddx-unserialize.html" ><B CLASS="function" >wddx_unserialize()</B ></A ></DT ><DT ><A HREF="function.wddx-packet-end.html" >wddx_packet_end</A > -- Ends a WDDX packet with the specified ID</DT ><DT ><A HREF="function.wddx-packet-start.html" >wddx_packet_start</A > -- Starts a new WDDX packet with structure inside it</DT ><DT ><A HREF="function.wddx-serialize-value.html" >wddx_serialize_value</A > -- Serialize a single value into a WDDX packet</DT ><DT ><A HREF="function.wddx-serialize-vars.html" >wddx_serialize_vars</A > -- Serialize variables into a WDDX packet</DT ><DT ><A HREF="function.wddx-unserialize.html" >wddx_unserialize</A > -- Unserializes a WDDX packet</DT ></DL ></DIV ></DIV ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.w32api-set-call-method.html" ACCESSKEY="P" >上一页</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >起始页</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.wddx-add-vars.html" ACCESSKEY="N" >下一页</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >w32api_set_call_method</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="funcref.html" ACCESSKEY="U" >上一级</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >wddx_add_vars</TD ></TR ></TABLE ></DIV ></BODY ></HTML >