PHPEveryday.com PHP and Web Development Tutorial
What are you looking for?


PHP Error Message

Warning: Invalid argument supplied for foreach() in /home/a3178292/public_html/article.php on line 213

Free Web Hosting

PHP WDDX: Simple Serialization Using PHP function


Web Distributed Data Exchange Step By Step tutorial - Part 8: Now, we try to serialize data use PHP's function. PHP have 2 function to serialize data into WDDX packet, wddx_serialize_value() wddx_serialize_vars(). these functions create a complete WDDX packet using just single line. oke, look following sample:
<?
$arrNum = array(1,2,3);

print wddx_serialize_value($arrNum, "This is my first wddx packet");

?>

The result is like this:

<wddxPacket version='1.0'>
  <header>
    <comment>This is my first wddx packet</comment>
  </header>
  <data>
    <array length='3'>
      <number>1</number>
      <number>2</number>
      <number>3</number>
    </array>
  </data>
</wddxPacket>

Another option to serialize data using wddx_serialize_vars(). We can put more than one variabel in this function, but we can not put header. This is example:

<?php
$arrNum = array(1,2,3);
$arrStr = array('PHP Undercover','Wiwit Siswoutomo');
$arr    = array($arrNum, $arrStr);


print wddx_serialize_vars('arrNum','arrStr','arr');

?>

The result:

<wddxPacket version='1.0'>
  <header/>
  <data>
    <struct>
      <var name='arrNum'>
        <array length='3'>
          <number>1</number>
          <number>2</number>
          <number>3</number>
        </array>
      </var>
      <var name='arrStr'>
        <array length='2'>
          <string>PHP Undercover</string>
          <string>Wiwit Siswoutomo</string>
        </array>
      </var>
      <var name='arr'>
        <array length='2'>
          <array length='3'>
            <number>1</number>
            <number>2</number>
            <number>3</number>
          </array>
          <array length='2'>
            <string>PHP Undercover</string>
            <string>Wiwit Siswoutomo</string>
          </array>
        </array>
      </var>
    </struct>
  </data>
</wddxPacket>


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


Tag: wddx. distributed data, serialization, wddx_serialize_value Category: PHP Application Post : April 30th 2008 Read: 2,961 Bookmark and Share

blog comments powered by Disqus


Database Tutorial
  • Learn PHP MySQL
  • Learn PHP ADOdb
  • Learn PHP Data Object/PDO
  • Learn PHP XML
  • Learn PHP SimpleXML
Security Tutorial
  • Learn PHP Security
  • Learn HTTP Authentication
  • Learn PHPSecureSite
Framework Tutorial
  • Learn CodeIgniter
  • Learn Joomla
  • Learn Smarty
  • Learn Zend Framework
Template Tutorial
  • Learn Joomla Template
  • Learn WordPress Template
API Tutorial
  • Learn Facebook
JS Framework Tutorial
  • Learn MooTools
  • Learn JQuery
AJAX Tutorial
  • Learn AJAX in 10 Minutes
  • Learn AJAX Client Side
  • Learn AJAX PHP
  • Learn AJAX Remote Server
  • Learn AJAX Repetitive
  • Learn AJAX MySQL
  • Learn AJAX Grid
Web Services Tutorial
  • Learn Web Services NuSOAP
  • Learn Web Services WSDL
  • Learn Web Services WSDL Array
  • Learn Web Services .NET Grid
  • Learn Web Services WDDX
Package Post
  • Joomla Intro
  • Joomla Component
  • Joomla Module
  • Joomla MVC
  • Joomla MVC Backend
  • PostNuke Intro
  • Zend Framework Intro
  • Zend Framework Action
  • Zend Framework Database
  • Zend Framework Registry
  • Zend Framework Config
  • Zend Framework Login
  • Zend Framework Session
  • PHP Array Tips
  • PHP File Tips
  • PHP Email
  • PHP Ms Excel
  • PHP Pattern
  • PHP SMS
  • Flash Database
  • PHP Multitier
  • jQuery Introduction
  • jQuery Selectors
  • Portable Web Server
  • Web Mobile Intro
  • Drupal Installation
  • Drupal Configuration