To bradburn at kiwi dot de:
PHP is only capable of serializing properly variables which match one of its native (scalar) types (See http://php.net/types). Which means that only variables of type booleans, integers, floating point numbers, string and NULL will be serialized properly.
I think there are two exceptions though:
- arrays are serialized by processing them recursively, so if its only composed of the above mentioned types, you should be fine.
- floating point numbers and integers may use the same representation while serialized in WDDX (I don't know much about WDDX, so I'm not 100% sure about this statement).
An interesting case would be whether objects can be serialized or not...
Funciones WDDX
Estas funciones permiten el uso de » WDDX.
Debe saber que todas las funciones que serializan variables usan el primer elemento de un array para determinar si este ha de serializarse en forma de array o como estructura. Si el primer elemento esta indexado por una cadena, se serializa como estructura, y en caso contrario, como array.
Example#1 Serializacion de un valor simple
<?php
print wddx_serialize_value("Ejemplo de PHP a paquete WDDX", "Paquete PHP");
?>
Este ejemplo producira:
<wddxPacket version='0.9'><header comment='Paquete PHP'/><data>
<string>Ejemplo de PHP a paquete WDDX</string></data></wddxPacket>
Example#2 Uso de paquetes incrementales
<?php
$pi = 3.1415926;
$packet_id = wddx_packet_start("PHP");
wddx_add_vars($packet_id, "pi");
/* Suponga que $ciudades se ha obtenido de una base de datos */
$ciudades = array("Austin", "Novato", "Seattle");
wddx_add_vars($packet_id, "ciudades");
$packet = wddx_packet_end($packet_id);
print $packet;
?>
Este ejemplo producira:
<wddxPacket version='0.9'><header comment='PHP'/><data><struct>
<var name='pi'><number>3.1415926</number></var><var name='ciudades'>
<array length='3'><string>Austin</string><string>Novato</string>
<string>Seattle</string></array></var></struct></data></wddxPacket>
Table of Contents
- wddx_add_vars — Finaliza un paquete WDDX con el identificador dado
- wddx_deserialize — Des-serializa un paquete WDDX
- wddx_packet_end — Finaliza un paquete WDDX con el identificador dado
- wddx_packet_start — Comienza un nuevo paquete WDDX con una estructura dentro
- wddx_serialize_value — Serializa un valor simple en un paquete WDDX
- wddx_serialize_vars — Serializa variables en un paquete WDDX
- wddx_unserialize — Unserializes a WDDX packet
WDDX
no at spam dot thx
13-Aug-2007 12:09
13-Aug-2007 12:09
Jimmy Wimenta
16-Jul-2004 03:53
16-Jul-2004 03:53
PHP's WDDX is useful only for exchanging data between PHP applications, but definetly not for exchanging data between different languages (which actually defeats the purpose of WDDX).
For example:
$hash1 = array ("2" => "Two", "4" => "Four", "5" => "Five");
$hash2 = array ("0" => "Zero", "1" => "One", "2" => "Two");
$hash1 will be serialized as hash, but
$hash2 will be serialized as array/list, because the key happen to be a sequence starting from 0.
Unless the library provide a way for users to specify the type, it can never be used for cross-platform data exchange.
Q1tum at hotmail dot com
21-Nov-2003 03:08
21-Nov-2003 03:08
To insert arrays into a wddx variable here is a fine way to do it:
<?php
$sql = 'SELECT * FROM example';
$query = mysql_query($sql, $db) or die(mysql_error());
while($result = mysql_fetch_array($query)) {
$id[] = $result[ 'id'];
$name[] = $result['name'];
$description[] = $result[$prefix . 'description'];
}
mysql_free_result($query);
wddx_add_vars($packet_id, "id");
wddx_add_vars($packet_id, "name");
wddx_add_vars($packet_id, "description");
$wddxSerializeValue = wddx_packet_end($packet_id);
?>
12-Sep-2003 05:29
wddx isn't 100% perl compatible .. I have an wddx file infront of me and it only works with php so better don't use it
pointsystems.com, sbarnum
04-Sep-2002 08:11
04-Sep-2002 08:11
a good FAQ on WDDX can be found here:
http://www.macromedia.com/v1/handlers/index.cfm?id=5622&method=full
bradburn at kiwi dot de
30-Jul-2002 05:02
30-Jul-2002 05:02
With ref to the above comment about typing, I have found that -- oddly enough -- PHP's WDDX supports the following WDDX types: null, boolean (true/false), number and string, *but* not date-time.
as an example, use the following values in an array that you then serialize:
$number = 5,
$null = NULL,
$bool = true,
$string = 'this is a string'.
they will all serialize correctly, e.g. the third entry comes out as:
<var name='bool'><boolean value='true'/></var>
i have tried with the 'official' format for WDDX 'datetime', e.g. '1998-9-15T09:05:32+4:0' (from the DTD @ http://www.openwddx.org/downloads/dtd/wddx_dtd_10.txt) but have only succeeded in getting this encoded as a 'string' type.
if anyone else has any more information on this, it would be welcome. i would like to store the variables in 'appropriate' fields in a database, and the fact that only datetime is not supported is slightly irritating -- otherwise it would be a very useful function.
philip at thepr()jects dot ()rg
17-Nov-2000 11:32
17-Nov-2000 11:32
Tutorial here :
XML and PHP. Part 1: Using the WDDX functions
http://www.phpbuilder.net/columns/jesus20000402.php3
djm at web dot us dot uu dot net
02-Mar-2000 01:50
02-Mar-2000 01:50
Here's a rewrite of the deserializing Perl code that uses variable names consistently with the serializing example. Sorry for any confusion....
<PRE>
#!/usr/bin/perl
use WDDX;
open(FP, "<cities.wddx");
undef $/; # Slurp the whole file.
$packet = <FP>;
close(FP);
$wddx = new WDDX;
$packet_id = $wddx->deserialize($packet);
$value = $packet_id->as_hashref();
print "pi is:<br>" . $value->{"pi"} . "<p>\n";
print "cities is:<br>\n";
$key = 0;
foreach $val (@{$value->{"cities"}}) {
print "$key => $val<br>\n";
$key++;
}
</PRE>
djm at web dot us dot uu dot net
02-Mar-2000 01:36
02-Mar-2000 01:36
I think it would be helpful for passing data between languages to show a direct translation of the above examples into Perl, using WDDX.pm 1.00 from CPAN. It took me awhile to figure out. To serialize:
<PRE>
#!/usr/bin/perl
use WDDX;
$wddx = new WDDX;
$packet_id = $wddx->struct({});
$pi = 3.1415926;
$packet_id->set("pi" => $wddx->number($pi));
# Suppose @cities came from database
@cities = ("Austin", "Novato", "Seattle");
$packet_id->set("cities" => $wddx->array([map $wddx->string($_), @cities]));
$packet = $wddx->serialize($packet_id);
open(FP, ">cities.wddx");
print FP $packet;
close(FP);
</PRE>
<P>
To deserialize:
<PRE>
#!/usr/bin/perl
use WDDX;
open(FP, "<cities.wddx");
undef $/; # Slurp the whole file.
$packet = <FP>;
close(FP);
$packet_id = new WDDX;
$wddx_obj = $packet_id->deserialize($packet);
$value = $wddx_obj->as_hashref();
print "pi is:<br>" . $value->{"pi"} . "<p>\n";
print "cities is:<br>\n";
$key = 0;
foreach $val (@{$value->{"cities"}}) {
print "$key => $val<br>\n";
$key++;
}
</PRE>
djm at web dot us dot uu dot net
19-Oct-1999 05:45
19-Oct-1999 05:45
Since there aren't any examples of reversing the process, here's one. If you had the packet produced by the above example (without the htmlentities() call), you could retrieve the values like this:
<pre>
$value = wddx_deserialize($packet);
print "pi is:<br>" . $value["pi"] . "<p>\n";
print "cities is:<br>\n";
while (list($key, $val) = each($value["cities"])) {
print "$key => $val<br>\n";
}
</pre>
which outputs:
<pre>
pi is:
3.1415926
cities is:
0 => Austin
1 => Novato
2 => Seattle
</pre>
