我从 yahoo Finance 中获取了白银的价值,并将当前价值增加了 0.10 .. 它显示了正确的结果..
$yql_base_url = "http://query.yahooapis.com/v1/public/yql?";
$params = array(
'q' => 'select * from html where url=@url and xpath=@xpath;',
'url' => 'http://finance.yahoo.com/q?s=XAGUSD%3DX&ql=1',
'xpath' => '//*[@id="yfs_g00_xagusd=x"]',
'env' => 'http://datatables.org/alltables.env',
'format' => 'json',
);
$yql_query_url = $yql_base_url . http_build_query($params);
$session = curl_init($yql_query_url);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
$json = curl_exec($session);
$phpObj = json_decode($json);
if ($phpObj->query->count > 0) {
$price = $phpObj->query->results->span->content;
}
?>
<div> <?php echo $price; ?> which is current value </div>
<div><?php echo $price + .10; ?> where 0.10 is added</div>
但是当我尝试黄金价格时,结果显示错误的输出,即 1 或 2
$yql_base_url = "http://query.yahooapis.com/v1/public/yql?";
$params = array(
'q' => 'select * from html where url=@url and xpath=@xpath;',
'url' => 'http://finance.yahoo.com/q?s=XAUUSD%3DX&ql=1',
'xpath' => '//*[@id="yfs_g00_xauusd=x"]',
'env' => 'http://datatables.org/alltables.env',
'format' => 'json',
);
$yql_query_url = $yql_base_url . http_build_query($params);
$session = curl_init($yql_query_url);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
$json = curl_exec($session);
$phpObj = json_decode($json);
if ($phpObj->query->count > 0) {
$price = $phpObj->query->results->span->content;
}
?>
<div> <?php echo $price; ?> which is current value</div>
<div> <?php echo $price + .10; ?> where 0.10 is added</div>
任何人都可以在这件事上帮助我..任何建议