PHP
  Home arrow PHP arrow Page 4 - Data Exchange with XML, WDDX and PHP
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Data Exchange with XML, WDDX and PHP
By: Vikram Vaswani, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 4
    2001-09-13

    Table of Contents:
  • Data Exchange with XML, WDDX and PHP
  • The Wonderful World Of WDDX
  • Polly Wants A Cracker
  • Humbert Redfinch-Northbottom The Third, I Presume?
  • Old Friends And New
  • Hip To Be Square
  • The Truth Is Out There
  • Money Talks
  • Closing Time

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Data Exchange with XML, WDDX and PHP - Humbert Redfinch-Northbottom The Third, I Presume?


    (Page 4 of 9 )

    The process of converting a data structure into WDDX is referred to as "serialization". Deserialization is, obviously, the reverse process. And your favourite language and mine, PHP, comes with a number of WDDX functions to accomplish both these (although you may need to recompile your PHP build to enable them.)

    The first of these is the wddx_serialize_value() function, used to create a WDDX packet containing a single value. The function also accepts an optional second parameter, which is used to generate a comment for the packet. So the following line of code

    <? echo wddx_serialize_value("Humbert Redfinch-Northbottom The Third", "Who da man?"); ?>
    would generate the WDDX fragment

    <wddxPacket version='1.0'> <header><comment>Who da man?</comment></header><data><string>Humbert Redfinch-Northbottom The Third</string></data></wddxPacket>
    Once a value has been serialized, it can be reconstituted into its original form with the wddx_deserialize() function, used to convert a WDDX packet into a native data structure. Consider the following example,

    <? // serialize$packet = wddx_serialize_value("Humbert Redfinch-Northbottom The Third");

    // deserialize$original_string = wddx_deserialize($packet);

    // printecho "My name is $original_string";?>
    which generates the output

    My name is Humbert Redfinch-Northbottom The Third
    This also works with arrays - the following code

    <? $star_wars = array("princess" => "Leia", "teacher" => "Yoda", "new hope" =>"Luke", "bad guy" => "Darth", "worse guy" => "The Emperor");

    $packet = wddx_serialize_value($star_wars);

    $data = wddx_deserialize($packet);

    echo $data['princess'];?>
    outputs

    Leia

    More PHP Articles
    More By Vikram Vaswani, (c) Melonfire


     

       

    PHP ARTICLES

    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security
    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...
    - Working with the Email Class in Code Igniter





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT