【问题标题】:I want to covert currency and I am using below function我想转换货币,我正在使用以下功能
【发布时间】:2015-04-10 20:07:22
【问题描述】:

我想兑换货币,我正在使用下面的函数

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);
}

但是这个功能对我不起作用并给出以下错误:

警告:file_get_contents(https://www.google.com/finance/converter?a=350&from=USD&to=YEN&meta=ei) [function.file-get-contents]:无法打开流:在第 6 行的 /home/hydra/public_html/recentportfolio/bookitla2/index.php 中找不到合适的包装器

请给我一个快速的解决方案。

【问题讨论】:

标签: php json


【解决方案1】:

请检查PHP 配置是否遵循allow_url_fopen 属性。允许用户从URL 获取内容应该为true。

或者,您可以使用CURL 而不是file_get_contents,因为这样做有点冒险。您也可以检查一下:

Should I allow 'allow_url_fopen' in PHP?

希望这能帮助您解决问题。

【讨论】:

    【解决方案2】:

    您的服务器必须将 allow_url_fopen 属性设置为 true。

    如果您不想更改设置,请查看CURL library。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-01-22
      • 2021-09-03
      • 1970-01-01
      • 1970-01-01
      • 2012-02-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多