HoHalla

Foxrate.org provides XML-RPC API to convert the currency from one to another. I needed it for a project to convert from Euro to Pound and vice-versa. I had once read about such a work in roshanbh.com.np so I finally thought to follow the same API.
After searching for some days, I came up with some code but had some problem for which I couldn't get any help. At last our senior friend from college, Sanjeev, added last two lines of code to make it run. Thanks Sanjeev.


<?php

require_once('lib/xmlrpc.inc');

//initialize client
$xmlrpc_client=new xmlrpc_client('/rpc','www.foxrate.org',80);
$xmlrpc_client->setDebug(3);//turn on debugging mode

//construct the request (xml-rpc message)

$xmlrpc_msg=new xmlrpcmsg('foxrate.currencyConvert', array(new xmlrpcval('USD','string'), new xmlrpcval('EUR','string'), new xmlrpcval(1,'double')));

//send the request
$xmlrpc_resp=$xmlrpc_client->send($xmlrpc_msg);

//working with the server's response

if (!$xmlrpc_resp)
{
print "<p>Could not connect to HTTP server.</p>";
}
elseif ($xmlrpc_resp->faultCode())
{
print "<p>XML-RPC Fault #" . $xmlrpc_resp->faultCode() . ": " .$xmlrpc_resp->faultString();
}
else
{
$result = $xmlrpc_resp->value();
$amount = $result->structmem('amount');
echo "<br><br>Amount Converted: ".$amount->scalarval();
}
?>

Share  Twitter

Comment

You need to be a member of HoHalla to add comments!

Join this Ning Network

Aashis Binod Khanal Comment by Aashis Binod Khanal on May 17, 2009 at 1:36pm
hanuman le kehi garcha

Translate This Network

Events

Music

Loading…

© 2010   Created by Shakeel Shrestha on Ning.   Create a Ning Network!

Badges  |  Report an Issue  |  Privacy  |  Terms of Service

Sign in to chat!