01 <?php
02 $str = file_get_contents("http://www.weather.gov.hk/textonly/forecast/chinesewx.htm");
03 ?>01 <?php
02 /* get weather information */
03 $str = file_get_contents("http://www.weather.gov.hk/textonly/forecast/chinesewx.htm");
04
05 /* extract weather string */
06 preg_match("/<!--天 氣 報 告-->(.*)<!--\/天 氣 報 告-->/s", $str, $result);
07
08 echo $result[1];
09 ?>01 <?php
02 $filename = "weather.dat"; // the file which save weather data
03
04 $check_time = filemtime($filename) + 3600;
05 if($check_time > time()){
06 include($filename);
07 }else{
08 /* get weather information */
09 $str = file_get_contents("http://www.weather.gov.hk/textonly/forecast/chinesewx.htm");
10
11 /* extract weather string */
12 preg_match("/<!--天 氣 報 告-->(.*)<!--\/天 氣 報 告-->/s", $str, $result);
13
14 /* write data to local file */
15 $fp = @fopen($filename, 'w');
16 @fwrite($fp, $result[1]);
17 @fclose($fp);
18
19 echo $result[1];
20 }
21 ?>