PHP Developer Channel :: 討論園地

您尚未登入。

#1 2005-03-19 05:59:23

dennis
New member
註冊日期: 2005-03-19
文章數: 1

請問擷取天氣或六合彩是怎樣整的??

請問擷取天氣或六合彩是怎樣整的??
可唔可以post出嚟比我參考下呀??

離線

 

#2 2005-03-19 20:47:11

Sam Tang
Administrator
來自: Hong Kong
註冊日期: 2005-03-01
文章數: 75
網站

Re: 請問擷取天氣或六合彩是怎樣整的??

先檢視來源網站的 html 碼,找出需要截取的字段,通常是一個特定行數或者前後有一些析別資料。
用 file() 或 file_get_contents() 取得來源網站內容,及用正規表達式截取所需字段,正規表達式的用法請看本站文章。

離線

 

#3 2005-03-21 23:49:05

Roger2hk
New member
來自: Cyber Land
註冊日期: 2005-03-21
文章數: 1
網站

Re: 請問擷取天氣或六合彩是怎樣整的??

希望以下的程式可以幫你~

程式碼:

<?php
$url='http://www.hko.gov.hk/textonly/forecast/chinesewx.htm'; 
$startc = 14;
$endc = 15;
$filec=file($url);
for ($ic=$startc;$ic<$endc;$ic++) {
$tempc = $filec[$ic];
$tempc = ereg_replace("天 文 台 錄 得:","天文台錄得:","$tempc");
$tempc = ereg_replace(" ","","$tempc");
$tempc = ereg_replace("
","","$tempc");
print "  $tempc";
}
$start = 15;
$end = 16;
$file=file($url);
for ($i=$start;$i<$end;$i++) {
$tempa = $file[$i];
$tempa = ereg_replace("氣 溫 : ","氣溫:","$tempa");
$tempa = ereg_replace(" 度","C","$tempa");
$tempa = ereg_replace(" ","","$tempa");
$tempa = ereg_replace("
","","$tempa");
print "  $tempa";
}
$startb = 16;
$endb = 17;
$fileb=file($url);
for ($ib=$startb;$ib<$endb;$ib++) {
$tempb = $fileb[$ib];
$tempb = ereg_replace("濕 度 : 百 分 之 ","濕度:","$tempb");
$tempb = ereg_replace(" ","","$tempb");
$tempb = ereg_replace("
","%","$tempb");
print "   $tempb";
}
?>

離線

 

論壇頁尾

Web Hosting
PHP Developer Channel
Powered by PunBB 1.2.9
© Copyright 2002–2005 Rickard Andersson