2 <head><title>xmlrpc - Agesort demo</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>
13 include_once __DIR__ . "/../../src/Autoloader.php";
14 PhpXmlRpc\Autoloader::register();
16 $inAr = array("Dave" => 24, "Edd" => 45, "Joe" => 37, "Fred" => 27);
17 print "This is the input data:<br/><pre>";
18 foreach($inAr as $key => $val) {
19 print $key . ", " . $val . "\n";
23 // create parameters from the input array: an xmlrpc array of xmlrpc structs
25 foreach ($inAr as $key => $val) {
26 $p[] = new PhpXmlRpc\Value(
28 "name" => new PhpXmlRpc\Value($key),
29 "age" => new PhpXmlRpc\Value($val, "int")
34 $v = new PhpXmlRpc\Value($p, "array");
35 print "Encoded into xmlrpc format it looks like this: <pre>\n" . htmlentities($v->serialize()) . "</pre>\n";
37 // create client and message objects
38 $req = new PhpXmlRpc\Request('examples.sortByAge', array($v));
39 $client = new PhpXmlRpc\Client("http://phpxmlrpc.sourceforge.net/server.php");
41 // set maximum debug level, to have the complete communication printed to screen
45 print "Now sending request (detailed debug info follows)";
46 $resp = $client->send($req);
48 // check response for errors, and take appropriate action
49 if (!$resp->faultCode()) {
50 print "The server gave me these results:<pre>";
51 $value = $resp->value();
52 $max = $value->arraysize();
53 for ($i = 0; $i < $max; $i++) {
54 $struct = $value->arraymem($i);
55 $name = $struct->structmem("name");
56 $age = $struct->structmem("age");
57 print htmlspecialchars($name->scalarval()) . ", " . htmlspecialchars($age->scalarval()) . "\n";
60 print "<hr/>For nerds: I got this value back<br/><pre>" .
61 htmlentities($resp->serialize()) . "</pre><hr/>\n";
63 print "An error occurred:<pre>";
64 print "Code: " . htmlspecialchars($resp->faultCode()) .
65 "\nReason: '" . htmlspecialchars($resp->faultString()) . '\'</pre><hr/>';