#native_company# #native_desc#
#native_cta#

WDDX Functions in PHP Page 3

By Jess M. Castagnetto
on July 30, 2000

The main steps involved in using
WDDX are: data serialization, packet creation, and data reconstruction
(deserialization). The WDDX functions in PHP provide 2 functions for packet
creation, 3 for variable serialization and one for deserialization. We will
discuss them in that order:
wddx_packet_start
Used to start a new WDDX packet for incremental addition of data.
Returns a packet identifier to be used with wddx_packet_end or any of the
serialization functions. This function takes an optional parameter to be used
as comment in the packet, and initializes it.

wddx_packet_end
Ends a WDDX packet specified by the identifier and returns the string
representation of it. WDDX packets are designed to be used for application to
application communication mainly, therefore there is no special formatting
(such a indentation or line breaks) between the different XML elements.
wddx_serialize_value
Generates the serialized representation of a single value. This function
accepts a variable to be serialized and and optional comment, it creates a
new packet containing the indicated variable. This will be a equivalent of
starting, adding and then ending a packet, when only one variable needs to be
serialized.
For example:

<?php

    $one_var "I was serialized on 2000-03-05";

    echo 
wddx_serialize_value($one_var"singleton");

?>



will output:

<wddxPacket version='0.9'><header comment='singleton'/><data>

<string>I was serialized on 2000-03-05</string></data></wddxPacket>

wddx_serialize_vars
Generates a WDDX packet containing the listed variables. It is similar to
wddx_serialize_value, but applied to a set of variables. It returns the string
representation of the WDDX packet. For example, if we have some variables with
the name and information and product purchased by a client:

<?php

$name "John Q. Public";

$info = array    (

        
"email"=>"[email protected]",

        
"address"=>"234 West 4th St. Apt 543",

        
"city"=>"New York City",

        
"state"=>"NY",

        
"zip"=>"10003"

        
);

$products = array ("56Kbps modem X-9""Thunder 11 graphic card");

echo wddx_serialize_vars("name""info""products");

?>



1
|
2
|
3
|
4
|
5
|
6
|
7
|
8