Jump to content

[SOLVED] PHP and web services


kam_uoc

Recommended Posts

Hi all,

I want to know how to work with web services in php.

I just want to convert currencies to USD to Rupee. I have found a web site which offers conversion as web service.

http://www.webservicex.net/CurrencyConvertor.asmx?op=ConversionRate

 

I have no clue how to connect this to my site. I haven't any knowledge on web services and php.

Any tutorial???

Thanks in advance.

 

Link to comment
https://forums.phpfreaks.com/topic/142594-solved-php-and-web-services/
Share on other sites

Here is an untested example

I hope it make sense or at least gives you an idea on how it works

 

<?php
//FROM TO CODE = http://www.webservicex.net/CurrencyConvertor.asmx?op=ConversionRate
//GET XML = http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?FromCurrency=USD&ToCurrency=GBP

$From="USD";
$To="GBP";
$URL = "http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?FromCurrency=$From&ToCurrency=$To";

//XML
$xml  = new SimpleXMLElement($URL);
$Rate  = $xml->double;


//OR use 
/*
$Rate = file_get_contents($URL);
if (preg_match('/<.*?>([^<]*)/', $Rate, $regs))
{
$Rate= $regs[1];
}
*/
echo $Rate;

?>

 

 

Now using XML you could get all the details for conversion from the remote site (http://www.webservicex.net/CurrencyConvertor.asmx?WSDL)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.