wddx examples

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.

Example #1 Serializing a single value with WDDX

echo wddx_serialize_value("PHP to WDDX packet example""PHP packet");

This example will produce:

<wddxPacket version='1.0'><header comment='PHP packet'/><data>
<string>PHP to WDDX packet example</string></data></wddxPacket>

Example #2 Using incremental packets with WDDX

$packet_id wddx_packet_start("PHP");

/* Suppose $cities came from database */
$cities = array("Austin""Novato""Seattle");

$packet wddx_packet_end($packet_id);

This example will produce:

<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>


If you want to serialize non-ASCII characters you have to convert your data to UTF-8 first (see utf8_encode() and iconv()).

add a note add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top