实时汇率函数,人民币转港币汇率,港币转人民币汇率
php中从百度抓取汇率的函数。
人民币转港币汇率
//人民币转港币汇率
function Get_Exchange_RMB2HKD()
{
$url = "http://www.baidu.com/s?rn=50&bs=%C8%CB%C3%F1%B1%D2%B6%D2%BB%BB%B8%DB%B1%D2%BB%E3%C2%CA+%BD%D3%BF%DA&f=8&wd=%C8%CB%C3%F1%B1%D2%B6%D2%BB%BB%B8%DB%B1%D2%BB%E3%C2%CA";
$html = file_get_contents($url);
$html = iconv("GBK", "utf-8",$html);
if (preg_match('/人民币元=(?P<exchange>[0-9\\.]+)/', $html, $regs)) {
$result = $regs[exchange];
} else {
$result = "0";
}
return $result;
}
港币转人民币汇率
//港币转人民币汇率
function Get_Exchange_HKD2RMB()
{
$url = "http://www.baidu.com/s?rn=50&bs=%C8%CB%C3%F1%B1%D2%B6%D2%BB%BB%B8%DB%B1%D2%BB%E3%C2%CA+%BD%D3%BF%DA&f=8&wd=%C8%CB%C3%F1%B1%D2%B6%D2%BB%BB%B8%DB%B1%D2%BB%E3%C2%CA";
$html = file_get_contents($url);
$html = iconv("GBK", "utf-8",$html);
if (preg_match('/港币=(?P<exchange>[0-9\\.]+)/', $html, $regs)) {
$result = $regs[exchange];
} else {
$result = "0";
}
return $result;
}
人民币转美元汇率
//人民币转美元汇率
function Get_Exchange_RMB2USD()
{
$url = "http://www.baidu.com/s?rn=50&bs=%B0%C4%C3%C5%B1%D2%BB%BB%C8%CB%C3%F1%B1%D2&f=8&wd=%C3%C0%D4%AA%BB%BB%C8%CB%C3%F1%B1%D2";
$html = file_get_contents($url);
$html = iconv("GBK", "utf-8",$html);
if (preg_match('/人民币元=(?P<exchange>[0-9\\.]+)/', $html, $regs)) {
$result = $regs[exchange];
} else {
$result = "0";
}
return $result;
}
美元转人民币汇率
//美元转人民币汇率
function Get_Exchange_USD2RMB()
{
$url = "http://www.baidu.com/s?rn=50&bs=%B0%C4%C3%C5%B1%D2%BB%BB%C8%CB%C3%F1%B1%D2&f=8&wd=%C3%C0%D4%AA%BB%BB%C8%CB%C3%F1%B1%D2";
$html = file_get_contents($url);
$html = iconv("GBK", "utf-8",$html);
if (preg_match('/美元=(?P<exchange>[0-9\\.]+)/', $html, $regs)) {
$result = $regs[exchange];
} else {
$result = "0";
}
return $result;
}
发表评论
| Trackback
