Logo         Community
  Trog
Services
The Company
Community
Columns
Your Account
Contact Us
 
 
Performing Remote Procedure Calls With PEAR XML_RPC
Learn to harness the power of XML-RPC in your PHP scripts

| Value Add |

The XML_RPC package is a PEAR package which provides an API for PHP developers to encode and decode XML-RPC requests and responses, and to build XML-RPC clients and servers. It's currently maintained by Stig Bakken, and is freely available from http://pear.php.net/package/XML_RPC

The XML_RPC package consists of a number of different objects, each serving a specific purpose. The most fundamental object, however, is the XML_RPC_Value() object, which is used to represent XML-RPC data values. This object supports all the simple and complex types outlined in the XML-RPC specification - to see how it works, type out and run the following script:


<?php
// include class
include ('XML/RPC.php');

// string
$value = new XML_RPC_Value("gargantuan gobbling geese", "string");

echo $value->serialize();
?>


When you view the output of the script, you should see something like this:

''.preg_replace(array('/  /', '/ /'), array('  ', '   '), '
<value>
<string>gargantuan gobbling geese</string>
</value>
').'
'

The output above is the XML-RPC representation of the string "gargantuan gobbling geese". It has been created by instantiating an object of the XML_RPC_Value() class, and passing the class constructor two arguments: the value to be encoded, and the type of data it is to be encoded as.

The XML-RPC specification supports a number of different data types, both simple and complex. The following example demonstrates the simple (or "scalar") types:


<?php
// include class
include ('XML/RPC.php');

// string
$value = new XML_RPC_Value("gargantuan gobbling geese", "string");

// int
$value = new XML_RPC_Value("2003", "int");

// float
$value = new XML_RPC_Value("12.67", "double");

// boolean
$value = new XML_RPC_Value("1", "boolean");

// datetime
$value = new XML_RPC_Value("20040829T22:12:00", "dateTime.iso8601");

// base64
$value = new XML_RPC_Value("1", "base64");
?>


The XML-RPC representation of each value can be obtained by calling the object's serialize() method, while the value itself can be retrieved with the scalarval() method. The following listing illustrates:


<?php
// include class
include ('XML/RPC.php');

// float
$value = new XML_RPC_Value("12.67", "double");

// prints "<value><double>12.67</double></value>"
echo $value->serialize();

// print "12.67"
echo $value->scalarval();
?>



How to do Everything with PHP & MySQL
How to do Everything with PHP & MySQL, the best-selling book by Melonfire, explains how to take full advantage of PHP's built-in support for MySQL and link the results of database queries to Web pages. You'll get full details on PHP programming and MySQL database development, and then you'll learn to use these two cutting-edge technologies together. Easy-to-follow sample applications include a PHP online shopping cart, a MySQL order tracking system, and a PHP/MySQL news publishing system.

Read more, or grab your copy now!


previous page more like this  print this article  next page
 
Search...
 
In trog...
Logging With PHP
Building A Quick-And-Dirty PHP/MySQL Publishing System
Output Buffering With PHP
Date/Time Processing With PHP
Creating Web Calendars With The PEAR Calendar Class
more...
 
In the hitg report...
Crime Scenes
Animal Attraction
Lord Of The Strings
more...
 
In boombox...
Patience - George Michael
Think Tank - Blur
My Private Nation - Train
more...
 
In colophon...
Hostage - Robert Crais
The Dead Heart - Douglas Kennedy
Right As Rain - George Pelecanos
more...
 
In cut!...
American Chai
The Core
Possession
more...
 
Find out how you can use this article on your own Web site!


Copyright © 1998-2018 Melonfire. All rights reserved
Terms and Conditions | Feedback