$html_path 設定要讀取的網頁
file_get_contents($html_path) 把讀趣的網頁轉成html存這字串中
highlight_string($result) 顯示html
eregi("123",$result.$temp) 把想要讀取的部分擷取出來
str_replace('123', '', $temp[0]);把不要的部分用空白取代
function exchange(){
$html_path = "http://consumer.chinatrust.com.tw/ch/int_rate/EX_RATE.html"; //國泰世華匯率
if ($html_path) {
$result = file_get_contents($html_path);
$result = iconv("big5","utf-8",$result);
//highlight_string($result); // 顯示html
}else {
//echo "錯誤 : 無法開啟網站!";
exit();
}
eregi('人 民 幣 / CNY 4.5760', $result, $temp); //設定過濾條件
$exchange_rate = array();
$exchange_rate[1] = str_replace('人 民 幣 / CNY ', '', $temp[0]);
$rate = 1/floatval($exchange_rate[1]);
return $rate;
}
參考文獻: http://blog.roodo.com/nextstep/archives/185546.html
沒有留言:
張貼留言