我写了下面的php代码从Yahoo Finance获取货币兑换率。PHP和curl从Yahoo财务获取货币汇率
我正在使用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);
?>
我的正则表达式有什么问题吗?
强制性响应:http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self -contained标签/ 1732454#1732454 – 2010-05-15 22:53:00