質問

PHPでパーサを作成する方法があったかどうか疑問に思っていましたが、このサイトからの値を取得する方法があった https://btc-e.com/api/2/btc_usd/ticker とPHPコードの変数として設定しますか?

PHPパーサーを見て、私が見つけた唯一のものは、ウェブサイトに関するすべての情報をエコーしたパーサーでした。

役に立ちましたか?

解決

そのURLはJSONの応答を返してから:

<?php

$content=file_get_contents("https://btc-e.com/api/2/btc_usd/ticker");
$data=json_decode($content);
//do whatever with $data now
?>
.

他のヒント

file_get_contents を使用してデータを取得できます。URLと json_decode 結果を解析して結果を解析するには、 JSON 配列、それはPHPによって解析されます。

例:

$bitcoin = json_decode(file_get_contents("https://btc-e.com/api/2/btc_usd/ticker"), true);
.

$bitcoin変数では、JSON文字列の値を持つ連想配列があります。

結果:

array(1) {
  ["ticker"]=>
  array(10) {
    ["high"]=>
    float(844.90002)
    ["low"]=>
    int(780)
    ["avg"]=>
    float(812.45001)
    ["vol"]=>
    float(13197445.40653)
    ["vol_cur"]=>
    float(16187.2271)
    ["last"]=>
    float(817.601)
    ["buy"]=>
    float(817.951)
    ["sell"]=>
    float(817.94)
    ["updated"]=>
    int(1389273192)
    ["server_time"]=>
    int(1389273194)
  }
}
.

そのページのデータは json と呼ばれます( JavaScriptオブジェクト表記法)(JSON MIMEタイプとして出力されていませんが、JSONのように定式化されています)。
データがJSONになることが NOW の場合は、Pageからの文字列(file_get_contents関数など)の文字列として入手し、それをjson_decode関数を使用して復号化します。

<?php
$dataFromPage = file_get_contents($url);
$data = json_decode($dataFromPage, true);
// Then just access the data from the assoc array like:
echo $data['ticker']['high'];
// or store it as you wish:
$tickerHigh = $data['ticker']['high'];
.

<?
function GetJsonFeed($json_url)
{
$feed = file_get_contents($json_url);
return json_decode($feed, true);
}
$LTC_USD = GetJsonFeed("https://btc-e.com/api/2/ltc_usd/ticker");
$LTC_USD_HIGH = $LTC_USD["ticker"]["last"];

$BTC_USD = GetJsonFeed("https://btc-e.com/api/2/btc_usd/ticker");
$BTC_USD_HIGH = $BTC_USD["ticker"]["last"];
?>
.
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top