Chapter 9. Helper functions

Table of Contents

Date functions
iso8601_encode
iso8601_decode
Easy use with nested PHP values
php_xmlrpc_decode
php_xmlrpc_encode
php_xmlrpc_decode_xml
Automatic conversion of php functions into xmlrpc methods (and vice versa)
wrap_xmlrpc_method
wrap_php_function
Functions removed from the library
xmlrpc_decode
xmlrpc_encode
Debugging aids
xmlrpc_debugmsg

XML-RPC for PHP contains some helper functions which you can use to make processing of XML-RPC requests easier.

Date functions

The XML-RPC specification has this to say on dates:

Don't assume a timezone. It should be specified by the server in its documentation what assumptions it makes about timezones.

Unfortunately, this means that date processing isn't straightforward. Although XML-RPC uses ISO 8601 format dates, it doesn't use the timezone specifier.

We strongly recommend that in every case where you pass dates in XML-RPC calls, you use UTC (GMT) as your timezone. Most computer languages include routines for handling GMT times natively, and you won't have to translate between timezones.

For more information about dates, see ISO 8601: The Right Format for Dates, which has a handy link to a PDF of the ISO 8601 specification. Note that XML-RPC uses exactly one of the available representations: CCYYMMDDTHH:MM:SS.

iso8601_encode

stringiso8601_encode(string$time_t,
 int$utc0);
 

Returns an ISO 8601 formatted date generated from the UNIX timestamp $time_t, as returned by the PHP function time().

The argument $utc can be omitted, in which case it defaults to 0. If it is set to 1, then the function corrects the time passed in for UTC. Example: if you're in the GMT-6:00 timezone and set $utc, you will receive a date representation six hours ahead of your local time.

The included demo program vardemo.php includes a demonstration of this function.

iso8601_decode

intiso8601_decode(string$isoString,
 int$utc0);
 

Returns a UNIX timestamp from an ISO 8601 encoded time and date string passed in. If $utc is 1 then $isoString is assumed to be in the UTC timezone, and thus the result is also UTC: otherwise, the timezone is assumed to be your local timezone and you receive a local timestamp.