【问题标题】:Get Currency Bid/Ask price for currencies in PHP using Yahoo Finance使用 Yahoo Finance 获取 PHP 货币的货币出价/要价
【发布时间】:2014-02-20 23:33:02
【问题描述】:

我发现/黑了(我的意思是黑了,我知道它不漂亮)下面的代码。

我要完成什么:

  • 同时获取 3 种货币的卖价/卖价
  • 货币为美元、巴西雷亚尔
  • EUR 基础货币为 ARS
  • 避免过于花哨,我只需要回显 6 个值(从基础货币对每种货币的出价/询价)

我能够获得我认为的平均价格,但我不确定如何获得出价/要价。

我确实注意到: - 如果您将 $usd_allData[1] 更改为 $usd_allData[2],您将获得日期 - 如果你将 $usd_allData[1] 更改为 $usd_allData[3],你会得到时间

如果您有任何见解或天才的闪光,请发送给我。

提前致谢!


<?php

/* USD
------------------------- */
$usd_from   = 'USD'; /*change it to your required currencies */
$usd_to     = 'ARS';
$usd_url = 'http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s='. $usd_from . $usd_to .'=X';
$usd_handle = @fopen($usd_url, 'r');

if ($usd_handle) {
    $usd_result = fgets($usd_handle, 4096);
    fclose($usd_handle);
}
$usd_allData = explode(',',$usd_result); /* Get all the contents to an array */
$usd_Value = $usd_allData[1];

/* EUR
------------------------- */
$eur_from   = 'EUR'; /*change it to your required currencies */
$eur_to     = 'ARS';
$eur_url = 'http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s='. $eur_from . $eur_to .'=X';
$eur_handle = @fopen($eur_url, 'r');

if ($eur_handle) {
    $eur_result = fgets($eur_handle, 4096);
    fclose($eur_handle);
}
$eur_allData = explode(',',$eur_result); /* Get all the contents to an array */
$eur_Value = $eur_allData[1];

/* BRL
------------------------- */
$brl_from   = 'BRL'; /*change it to your required currencies */
$brl_to     = 'ARS';
$brl_url = 'http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s='. $brl_from .     $brl_to .'=X';
$brl_handle = @fopen($brl_url, 'r');

if ($brl_handle) {
    $brl_result = fgets($brl_handle, 4096);
    fclose($brl_handle);
}
$brl_allData = explode(',',$brl_result); /* Get all the contents to an array */
$brl_Value = $brl_allData[1];

echo (
    $usd_Value . '<br><hr>' .
    $eur_Value . '<br><hr>' .
    $brl_Value 
)

?>

【问题讨论】:

    标签: php yahoo-finance currency-exchange-rates


    【解决方案1】:

    您是否考虑过 Google 而不是 Yahoo? Need API for currency converting

    我也只需要 print_r() 你的数组来查看结果,而不是逐项挑选。

    【讨论】:

      【解决方案2】:

      你让我很开心。对数组进行 'print_'r 操作,然后快速进行 Google 搜索,我找到了这篇题为“Yahoo Finance (hidden) API”的文章

      原来这个位是关键:

      http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s=

      具体如下:

      &f=

      紧随其后的字母获取相应的变量。所以,这得到 sl1, d1, t1。

      sl1d1t1

      将其更改为以下位 (b2, b3),获取实时出价和要价(准确度如何,我不知道)

      sl1d1t1b2b3

      非常,非常,非常感谢!

      【讨论】:

        猜你喜欢
        • 2011-02-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-08-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多