2 <head><title>xmlrpc</title></head>
6 <h2>Send an array of 'name' => 'age' pairs to the server that will send it back sorted.</h2>
8 <h3>The source code demonstrates basic lib usage, including handling of xmlrpc arrays and structs</h3>
14 $inAr = array("Dave" => 24, "Edd" => 45, "Joe" => 37, "Fred" => 27);
16 print "This is the input data:<br/><pre>";
17 while (list($key, $val) = each($inAr)) {
18 print $key . ", " . $val . "\n";
22 // create parameters from the input array: an xmlrpc array of xmlrpc structs
24 foreach ($inAr as $key => $val) {
25 $p[] = new xmlrpcval(array("name" => new xmlrpcval($key),
26 "age" => new xmlrpcval($val, "int")), "struct");
28 $v = new xmlrpcval($p, "array");
29 print "Encoded into xmlrpc format it looks like this: <pre>\n" . htmlentities($v->serialize()) . "</pre>\n";
31 // create client and message objects
32 $f = new xmlrpcmsg('examples.sortByAge', array($v));
33 $c = new xmlrpc_client("/server.php", "phpxmlrpc.sourceforge.net", 80);
35 // set maximum debug level, to have the complete communication printed to screen
39 print "Now sending request (detailed debug info follows)";
42 // check response for errors, and take appropriate action
43 if (!$r->faultCode()) {
44 print "The server gave me these results:<pre>";
46 $max = $v->arraysize();
47 for ($i = 0; $i < $max; $i++) {
48 $rec = $v->arraymem($i);
49 $n = $rec->structmem("name");
50 $a = $rec->structmem("age");
51 print htmlspecialchars($n->scalarval()) . ", " . htmlspecialchars($a->scalarval()) . "\n";
54 print "<hr/>For nerds: I got this value back<br/><pre>" .
55 htmlentities($r->serialize()) . "</pre><hr/>\n";
57 print "An error occurred:<pre>";
58 print "Code: " . htmlspecialchars($r->faultCode()) .
59 "\nReason: '" . htmlspecialchars($r->faultString()) . '\'</pre><hr/>';