note 81345 added to ref.wddx
| From: | egbertteeselink at osu1 dot php dot net | Date: | Sat, 23 Feb 2008 18:49:37 +0000 |
| Subject: | note 81345 added to ref.wddx | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-136440@lists.php.net to get a copy of this message | ||
If your PHP doesn't have wddx support installed, and you need it, and you don't want to
install PEAR just for wddx, try this short piece of code, based on SimpleXML:
//can read any wddx file generated from php arrays. assumes var elements are only inside struct
elements and that only one packet exists.
function wddx_read_node($node, $type)
{
switch($type)
{
case "boolean":
return (string)$node;
case "number":
case "binary":
case "string":
return (string)$node;
case "null":
return null;
case "array":
$a = array();
foreach($node as $subtype => $subnode)
{
$a[] = wddx_read_node($subnode, $subtype);
}
return $a;
case "struct":
$a = array();
foreach($node as $subtype => $subnode)
{
list($key, $value) = wddx_read_node($subnode, $subtype); //must be a var element
$a[$key] = $value;
}
return $a;
case "var":
list($subnode, $subtype) = getchild($node);
return array((string)$node["name"], wddx_read_node($subnode, $subtype));
case "data":
list($subnode, $subtype) = getchild($node);
return wddx_read_node($subnode, $subtype);
}
}
function wddx_read($string)
{
$xml = simplexml_load_string($string);
$d = wddx_read_node($xml->data, "data");
return $d;
}
important notice: this one may not work with all wddx input. multiple packets or variables outside a
"struct" are not supported. basically, you always get a PHP (associative) array, never
something else. feel free to make additions.
----
Server IP: 87.54.44.10
Probable Submitter: 90.184.121.185
----
Manual Page -- http://www.php.net/manual/en/ref.wddx.php
Edit -- https://master.php.net/note/edit/81345
Del: integrated -- https://master.php.net/note/delete/81345/integrated
Del: useless -- https://master.php.net/note/delete/81345/useless
Del: bad code -- https://master.php.net/note/delete/81345/bad+code
Del: spam -- https://master.php.net/note/delete/81345/spam
Del: non-english -- https://master.php.net/note/delete/81345/non-english
Del: in docs -- https://master.php.net/note/delete/81345/in+docs
Del: other reasons-- https://master.php.net/note/delete/81345
Reject -- https://master.php.net/note/reject/81345
Search -- https://master.php.net/manage/user-notes.php