More newline fixes
[plcapi.git] / demo / client / agesort.php
1 <html>
2 <head><title>xmlrpc</title></head>
3 <body>
4 <h1>Agesort demo</h1>
5
6 <h2>Send an array of 'name' => 'age' pairs to the server that will send it back sorted.</h2>
7
8 <h3>The source code demonstrates basic lib usage, including handling of xmlrpc arrays and structs</h3>
9
10 <p></p>
11 <?php
12 include "xmlrpc.inc";
13
14 $inAr = array("Dave" => 24, "Edd" => 45, "Joe" => 37, "Fred" => 27);
15 reset($inAr);
16 print "This is the input data:<br/><pre>";
17 while (list($key, $val) = each($inAr)) {
18     print $key . ", " . $val . "\n";
19 }
20 print "</pre>";
21
22 // create parameters from the input array: an xmlrpc array of xmlrpc structs
23 $p = array();
24 foreach ($inAr as $key => $val) {
25     $p[] = new xmlrpcval(array("name" => new xmlrpcval($key),
26         "age" => new xmlrpcval($val, "int")), "struct");
27 }
28 $v = new xmlrpcval($p, "array");
29 print "Encoded into xmlrpc format it looks like this: <pre>\n" . htmlentities($v->serialize()) . "</pre>\n";
30
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);
34
35 // set maximum debug level, to have the complete communication printed to screen
36 $c->setDebug(2);
37
38 // send request
39 print "Now sending request (detailed debug info follows)";
40 $r = &$c->send($f);
41
42 // check response for errors, and take appropriate action
43 if (!$r->faultCode()) {
44     print "The server gave me these results:<pre>";
45     $v = $r->value();
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";
52     }
53
54     print "<hr/>For nerds: I got this value back<br/><pre>" .
55         htmlentities($r->serialize()) . "</pre><hr/>\n";
56 } else {
57     print "An error occurred:<pre>";
58     print "Code: " . htmlspecialchars($r->faultCode()) .
59         "\nReason: '" . htmlspecialchars($r->faultString()) . '\'</pre><hr/>';
60 }
61
62 ?>
63 </body>
64 </html>