PHP WDDX: Unserializing Data


Web Distributed Data Exchange Step By Step tutorial - Part 10: You can unserialize data by PHP's function, wddx_deserialize(). This function will unserialize WDDX packet and returns the corresponding native PHP data type. It is simple, look this sample:
<?php
// example data
$arrBooks = array(array('id'=>1,'title'=>'PHP Undercover'),
                  array('id'=>2,'title'=>'PHP Webservices'),
				  array('id'=>3,'title'=>'Zend Framework')
				  );

// add header
$wddxst = wddx_packet_start('We build a start');

// add some variables
$rowCount   = count($arrBooks);
$fieldCount = 2;

wddx_add_vars($wddxst,'rowCount','fieldCount');

// add complex variable 
$i = 0;
for($i=0;$i<$rowCount;$i++){
  $varname = 'book'.$i;
  $$varname = $arrBooks[$i];

  wddx_add_vars($wddxst, $varname);
}

$packet = wddx_packet_end($wddxst);

// unserialize
$data = wddx_deserialize($packet);
// test
print_r($data);
?>

The result:

Array ( 
  [rowCount] => 3 
  [fieldCount] => 2 
  [book0] => Array ( [id] => 1 [title] => PHP Undercover ) 
  [book1] => Array ( [id] => 2 [title] => PHP Webservices ) 
  [book2] => Array ( [id] => 3 [title] => Zend Framework ) 
)


Series this article:
PHP WDDX: Introduction
PHP WDDX: Understanding Anatomy of WDDX
PHP WDDX: Understanding Data Elements
PHP WDDX: Understanding Simple Data Type
PHP WDDX: Using Array Elements
PHP WDDX: Struct Element
PHP WDDX: Recordset Element
PHP WDDX: Simple Serialization Using PHP function
PHP WDDX: Complex Serialization
PHP WDDX: Unserializing Data
PHP WDDX: Creating Web Service Server
PHP WDDX: Creating Web Service Client

Bookmark and Share Tag: wddx. distributed data, unserialization Category: PHP Application Post : April 30th 2008 Read: 21,259

advertisements


blog comments powered by Disqus