phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


PHP WDDX: Simple Serialization Using PHP function

Tag: wddx. distributed data, serialization, wddx_serialize_value   Category: PHP Application
post: 30 Apr 2008 read: 240


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

| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
mod_rewrite - Part 1: create your "fantasy" URL

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


615
posting