【发布时间】:2011-02-19 23:36:53
【问题描述】:
我写了下面的 php sn-p 从 Yahoo Finance 获取货币兑换率。
我正在使用 curl 来获取数据。 假设我想将美元 (USD) 转换为印度卢比 (INR),则 url 为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);
?>
我的正则表达式有问题吗?
【问题讨论】:
标签: php regex curl web-scraping