HomePHP Page 5 - Data Exchange with XML, WDDX and PHP
Old Friends And New - PHP
You may never have heard of it before - but if your job involvesexchanging data between different servers and applications, you're going tobe hearing a lot about it very soon. Find out how WDDX makes it possible tocreate and transmit platform-neutral data structures across the Web, andhow it can be combined with PHP to create a whole new generation of Webapplications (including new content syndication and financial updateservices).
You can serialize more than one variable at a time with the wddx_serialize_vars() function, which accepts a list of variable names and creates a single WDDX packet representing the entire set. The code snippet
<header/><data><struct><var name='friends'><array length='6'><string>Rachel</string><string>Phoebe</string><string>Monica</string><string>Chandler</string><string>Joey</string><string>Ross</string></array>/var><var name='total'><number>34238</number></var><var name='phrase'><string>The wild blue fox jumped over the indigo submarine</string></var><var name='error_flag'><boolean value='false'/></var></struct></data></wddxPacket>
Note that the line breaks have been added by me for clarity - PHP generates the entire packet as a single string.
You can also serialize an associative array
// set up array$star_wars = array('princess' => 'Leia', 'teacher' => 'Yoda', 'new hope' =>'Luke', 'bad guy' => 'Darth', 'worse guy' => 'The Emperor');// serializeecho wddx_serialize_vars("star_wars");?>
Note that when this structure is deserialized, it will result in an associative array containing the single key "star_wars", which points to an array of the original values. The following example demonstrates this: