1 private function get_new_earthquake(){ 2 // global $dbconn; 3 $u="http://www.ceic.ac.cn/speedsearch?time=1"; 4 $nodes_url=$u; 5 if($debug_mode)echo "URL is ".$nodes_url."<br>"; 6 7 $file_content = file_get_contents($nodes_url); 8 // echo "file content is ".$file_content; 9 // $file_content=GetGB2312String($file_content); 10 // if($debug_mode)echo htmlspecialchars($file_content); 11 if(strlen($file_content)==0){ 12 if($debug_mode)echo "没有此网页:$nodes_url"; 13 exit; 14 } 15 // <table border="0" cellpadding="0" cellspacing="0" class="speed-table1"> 16 preg_match_all("%<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"speed-table1\">(.+?)</table>%s",$file_content,$temp); 17 if($debug_mode){ 18 print_r($temp); 19 } 20 preg_match_all("%<td align=\"(.+?)\">(.+?)</td>%s",$temp[1][0],$temp2); 21 if($debug_mode){ 22 print_r($temp2); 23 } 24 echo "<BR>"; 25 $content=‘‘; 26 if($temp2[2][1]){ 27 $content="最新的地震信息:".$temp2[2][1]."发生了震级为 ".$temp2[2][0]."级的地震"."\n"; 28 $content.="发震时刻:".$temp2[2][1]."\n"; 29 $content.="震级(M):".$temp2[2][0]."\n"; 30 $content.="纬度(°):".$temp2[2][2]."\n"; 31 $content.="经度(°):".$temp2[2][3]."\n"; 32 $content.="深度(千米):".$temp2[2][4]."\n"; 33 $content.="参考位置:".$temp2[2][5]."\n"; 34 } 35 return $content; 36 }
1 c ase "dz": 2 $contentStr = $this->get_new_earthquake(); 3 if(!$contentStr)$contentStr="谢天谢地,今天没有发生地震!"; 4 $this->weixin_output($contentStr,$textTpl,$fromUsername,$toUsername,$time); 5 break;