Introduction ¶
This extension will help to find out current currency conversion rate. This extension uses Yahoo's currency conversion API.
Why Use It ¶
- Reliable Rate, Uses Yahoo API
- Conversion without curreny code(from country code)
- Caching of rate, to avoid connecting to Yahoo again and again ( Working on caching )
Requirements ¶
- PHP version 5.4 or later
- Curl Extension (Optional)
- Yii 2.0
Installation ¶
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist imanilchaudhari/yii2-currency-converter "dev-master"
or add
"imanilchaudhari/yii2-currency-converter": "dev-master"
to the require section of your composer.json
file.
Usage ¶
Once the extension is installed, simply use it in your code by :
use imanilchaudhari\CurrencyConverter\CurrencyConverter;
$converter = new CurrencyConverter();
$rate = $converter->convert('USD', 'NPR');
print_r($rate); // it will print current Nepalese currency (NPR) rate according to USD
It doesn't work
`
PHPUndefined offset: 1
in ...\vendor\imanilchaudhari\yii2-currency-converter\Provider\YahooApi.php at line 37
282930313233343536373839 $ch = curl_init();
$timeout = 0; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)'); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $rawdata = curl_exec($ch); curl_close($ch); return explode(',', $rawdata)[1]
@Geus
As of recent changes on Yahoo Terms of Service. As such, the service is being discontinued.
You can use other api providers.
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.