1 <?php require_once __DIR__ . "/_bootstrap.php"; ?><html lang="en">
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>
10 <p>You can see the source to this page here: <a href="agesort.php?showSource=1">agesort.php</a></p>
13 $inAr = array("Dave" => 24, "Edd" => 45, "Joe" => 37, "Fred" => 27);
14 print "This is the input data:<br/><pre>";
15 foreach ($inAr as $key => $val) {
16 print $key . ", " . $val . "\n";
20 // Create parameters from the input array: an xmlrpc array of xmlrpc structs
22 foreach ($inAr as $key => $val) {
23 $p[] = new PhpXmlRpc\Value(
25 "name" => new PhpXmlRpc\Value($key),
26 "age" => new PhpXmlRpc\Value($val, "int")
31 $v = new PhpXmlRpc\Value($p, "array");
32 print "Encoded into xmlrpc format it looks like this: <pre>\n" . htmlentities($v->serialize()) . "</pre>\n";
34 // create client and message objects
35 $req = new PhpXmlRpc\Request('examples.sortByAge', array($v));
36 $client = new PhpXmlRpc\Client(XMLRPCSERVER);
38 // set maximum debug level, to have the complete communication printed to screen
42 print "Now sending request (detailed debug info follows)";
43 $resp = $client->send($req);
45 // check response for errors, and take appropriate action
46 if (!$resp->faultCode()) {
47 print "The server gave me these results:<pre>";
48 $value = $resp->value();
49 foreach ($value as $struct) {
50 $name = $struct["name"];
51 $age = $struct["age"];
52 print htmlspecialchars($name->scalarval()) . ", " . htmlspecialchars($age->scalarval()) . "\n";
55 print "<hr/>For nerds: I got this value back<br/><pre>" .
56 htmlentities($resp->serialize()) . "</pre><hr/>\n";
58 print "An error occurred:<pre>";
59 print "Code: " . htmlspecialchars($resp->faultCode()) .
60 "\nReason: '" . htmlspecialchars($resp->faultString()) . '\'</pre><hr/>';