0

I want to covert currency and I am using below function

function convertCurrency($amount, $from, $to){
    $url  = "https://www.google.com/finance/converter?a=$amount&from=$from&to=$to&meta=ei";
    $data = file_get_contents($url);
    preg_match("/<span class=bld>(.*)<\/span>/",$data, $converted);
    $converted = preg_replace("/[^0-9.]/", "", $converted[1]);
    return round($converted, 3);
}

But this function is not working for me and giving the below error:

Warning: file_get_contents(https://www.google.com/finance/converter?a=350&from=USD&to=YEN&meta=ei) [function.file-get-contents]: failed to open stream: no suitable wrapper could be found in /home/hydra/public_html/recentportfolio/bookitla2/index.php on line 6

Please give me a quick solution for this.

user3432211
  • 21
  • 1
  • 7
  • possible duplicate of [failed to open stream: no suitable wrapper could be found](http://stackoverflow.com/questions/19527150/failed-to-open-stream-no-suitable-wrapper-could-be-found) – Frank Apr 10 '15 at 11:49
  • this same code working perfect on localhost and not working on server – user3432211 Apr 10 '15 at 11:52

2 Answers2

0

Please check the PHP configuration for following allow_url_fopen property.It should be true to allow user to fetch the content from URl.

Alternative, you can use CURL instead of file_get_contents because it's bit risky to allow that.You can also check this :

Should I allow 'allow_url_fopen' in PHP?

Hope this will help you to solve the issue.

Community
  • 1
  • 1
Toretto
  • 4,721
  • 5
  • 27
  • 46
0

Your server must have the allow_url_fopen property set to true.

If you don't want to change your settings check CURL library.