我编写了以下 php 代码片段以从 Yahoo Finance 获取货币兑换率。
我正在使用 curl 来获取数据。假设,我想从美元 (USD) 转换为印度国家卢比 (INR),那么网址是http://in.finance.yahoo.com/currency/convert?amt=1&from=USD&to=INR&submit=和印度卢比值显示为 45.225。但是,如果我运行我的代码,我得到的值是 452.25。为什么会出现这种差异?
<?php
$amount = $_GET['amount'];
$from = $_GET['from'];
$to = $_GET['to'];
$url = "http://in.finance.yahoo.com/currency/convert?amt=".$amount."&from=".$from."&to=".$to;
$handle = curl_init($url);
curl_setopt ($handle, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($handle);
if(preg_match_all('/<td class="yfnc_tabledata1"><b>(?:[1-9]\d+|\d)(?:\.\d\d)?/',$data,$matches))
{
print_r($matches[0][1]);
}
else
{
echo "Not found !";
}
curl_close($handle);
?>
我的正则表达式有问题吗?