To extract data from an XML-RPC response and transform them into PHP variables, we will use xmlrpc_encode_request()'
s complementary function, xmlrpc_decode()
. xmlrpc_encode_request()
was smart enough to take variables, whether they are primitive variables, arrays, or structures, and transform them into an XML-RPC request.
xmlrpc_decode()
will take an XML-RPC response, look for the type of data being returned for example, whether they are simple primitives, structures, or arrays, and return either a straight PHP value (if primitive) or an array of values (if they are an XML-RPC struct or array). xmlrpc_decode()
will also process XML-RPC response errors. Using another function, xmlrpc_is_fault()
, we can evaluate the return value to see if it is an error and handle them accordingly.
Let’s create a function to demonstrate both xmlrpc_decode()
and xmlrpc_is_fault()
.
function processXMLRPCResponse($xmlrpcResponse) { $data = xmlrpc_decode($xmlrpcResponse); if (xmlrpc_is_fault...