1. php在日歷上面顯示天氣預報這么顯示 我日歷代碼已經寫好在下面這么添加天氣預報
直接用中國天氣網的插件就可以
2. 誰有WAP、PHP版的天氣預報源碼最好能預報到「市級」的。或者能給個查看本縣天氣的wap網址.我做地方論壇
PHP好像沒有站寫,JSP和aspx的網站寫出來的都好多,很多站有共享,大把站有,我也寫一種asp的,垃圾程序,如果要插你的程序里還要看你的程序代碼如何,如果是單獨的天氣程序可以搞小偷,這方便簡單
3. 怎麼利用php的api獲得城市新浪天氣
<?php
//發送瀏覽器頭信息告訴瀏覽器本頁面的編碼防止亂碼
header("Content-type:text/html;charset=utf-8");
$city='上海';
//定義介面地址
$encode_url='http://php.weather.sina.com.cn/xml.php?city='.urlencode(mb_convert_encoding($city,'gb2312','utf8')).'&password=DJOYnieT8234jlsK&day=1';
//請求介面地址獲取xml
$xml_source=file_get_contents($encode_url);
//var_mp($xml_source);
//利用simplexml解析類將xml轉成對象
$xml_object=simplexml_load_string($xml_source);
//var_mp($xml_object);
echo$xml_object->Weather->status1;
你可以隨便調試 記得獎勵哦
4. 如何使用PHP調用API介面實現天氣查詢功能
最近在做微信公眾平台測試時,想在裡面子菜單上添加查詢未來幾天(包括今天)天氣的功能,就查找了下好用的天氣預報查詢介面API,使用比較多的有:國家氣象局天氣介面、新浪天氣預報介面、網路天氣預報介面、google天氣介面、Yahoo天氣介面等等,我使用的是網路提供的免費天氣查詢介面API,下面與大家分享下...
1、查詢方式:
網路提供的是根據緯度和城市名查詢天氣情況
2、介面事例:
5. 怎麼用php抓取天氣預報先說下思路,再舉個例子。
我昨天剛做了個,本來打算自己用,你既然問,就分享了吧!
PS:因為我是菏澤人,所以,如果你什麼都不填,就顯示菏澤天氣。
如果想顯示別的,直接輸入就行,比如"香港",然後提交就OK了
http://young.boustead.e.cn/data/shunzi/tq.php
不知道是否合乎樓主的意願(不用JS)
6. 怎樣用php自動在24點時將天氣情況加入資料庫
找一段天氣預報代碼,將返回的json代碼通過連接語句插入到資料庫中。
然後每天24點定時訪問這個php鏈接就可以了。
7. php怎麼抓取天氣預報
可以藉由php的api或者preg_match_all偷偷擷取去達成目的
這里給你一段我給台灣朋友有一段源碼
<?php
header("Content-Type:text/html;charset=utf-8");
functiongetWeather($city){
$toURL="
$city.htm";
$post=array();
$ch=curl_init();
$options=array(
CURLOPT_REFERER=>'',
CURLOPT_URL=>$toURL,
CURLOPT_VERBOSE=>0,
CURLOPT_RETURNTRANSFER=>true,
CURLOPT_USERAGENT=>"Mozilla/4.0(compatible;)",
CURLOPT_POST=>true,
CURLOPT_POSTFIELDS=>http_build_query($post),
);
curl_setopt_array($ch,$options);
$result=curl_exec($ch);
curl_close($ch);
//連接中央氣象局
echo'<pre>';
preg_match_all('/<tableclass="FcstBoxTable01"[^>]*[^>]*>(.*)</div>/si',$result,$matches,PREG_SET_ORDER);
preg_match_all('/<tdnowrap="nowrap"[^>]*[^>]*>(.*)</td>/si',$matches[0][1],$m1,PREG_SET_ORDER);
$m2=explode('</td>',$m1[0][1]);
//print_r($m2);//取得每日資料m2[0~6]
$weather=array();
for($i=0;$i<=6;$i++){
preg_match_all('/src=[^>]*[^>](.*)/si',$m2[$i],$m5,PREG_SET_ORDER);//取得天氣圖檔
$m6=explode('"',$m5[0][0]);
$wi='
($m6[1],'../../');
$wtitle=$m6[3];
print_r($wtitle);
$weather[$i]['date']=date("m-d",mktime(0,0,0,date("m"),date("d")+$i,date("Y")));
$weather[$i]['temperature']=trim(strip_tags($m2[$i]));
$weather[$i]['title']=$wtitle;
$weather[$i]['img']=$wi;
}
return($weather);
}
$weather=getWeather("Taipei_City");
print_r($weather);
//header("Location:loc.php");
?>
首先
$toURL="http://www.cwb.gov.tw/V7/forecast/taiwan/inc/city/$city.htm";
這里是讀取資料的網址
上面的是台灣中央氣象局
preg_match_all('/<tableclass="FcstBoxTable01"[^>]*[^>]*>(.*)</div>/si',$result,$matches,PREG_SET_ORDER);
preg_match_all('/<tdnowrap="nowrap"[^>]*[^>]*>(.*)</td>/si',$matches[0][1],$m1,PREG_SET_ORDER);
這里是截取台灣中央氣象局網頁信息table class="FcstBoxTable01" [^>]*[^>]*>(.*)</div>的資料以及<td nowrap="nowrap" [^>]*[^>]*>(.*)</td>的資料分別是1天跟1周
$m2=explode('</td>',$m1[0][1]);
//print_r($m2);//取得每日資料m2[0~6]
這里是取得每日的資料
preg_match_all('/src=[^>]*[^>](.*)/si',$m2[$i],$m5,PREG_SET_ORDER);//取得天氣圖檔
這里是取得天氣的圖檔
$m6=explode('"',$m5[0][0]);
$wi='
($m6[1],'../../');
$wtitle=$m6[3];
print_r($wtitle);
$weather[$i]['date']=date("m-d",mktime(0,0,0,date("m"),date("d")+$i,date("Y")));
$weather[$i]['temperature']=trim(strip_tags($m2[$i]));
$weather[$i]['title']=$wtitle;
$weather[$i]['img']=$wi;
這里是返回的網址,日期,標題,圖檔等等的資料
$weather=getWeather("Taipei_City");
print_r($weather);
然後這里是顯示出地區的一周天氣預報
結論:就是如果你想從網站上面截取天氣預報
在php可以是用preg_match_all(網頁的表格table,表格的列數tr,表格的欄位td,或者更加廣泛的標簽div等等獲取)
8. php獲取天氣預報的代碼
<?php
$URLStyle="http://flash.weather.com.cn/wmaps/xml/%s.xml";
$chinaURL=sprintf($URLStyle,"china");
$chinaStr=file_get_contents($chinaURL);
$chinaObj=simplexml_load_string($chinaStr);
$chinaObjLen=count($chinaObj->city);
echo"chinaObjLen=".$chinaObjLen." ";
for($i=0;$i<$chinaObjLen;$i++){
//遍歷省一級節點,共37個
$level1=$chinaObj->city[$i]["pyName"];
$shengjiURL=sprintf($URLStyle,$level1);
$shengjiStr=file_get_contents($shengjiURL);
//echo$shengjiStr;
$shengjiObj=simplexml_load_string($shengjiStr);
$shengjiObjLen=count($shengjiObj->city);
//echo$chinaObj->city[$i]["quName"];
//echo"".$shengjiObjLen." ";
for($j=0;$j<$shengjiObjLen;$j++){
//遍歷市一級節點
$level2=$shengjiObj->city[$j]["pyName"];
$shijiURL=sprintf($URLStyle,$level2);
$shijiStr=file_get_contents($shijiURL);
//echo$shijiStr;
$shijiObj=simplexml_load_string($shijiStr);
//直轄市和海南、台灣、釣魚島等沒有縣級節點
if(!$shijiObj){
echo"WARNNING:notexsitnextlevelnode.-".$level1."-".$shijiURL." ";
echo'"'.$shengjiObj->city[$j]["cityname"].'"=>';
echo$shengjiObj->city[$j]["url"].", ";
continue;
}
$shijiObjLen=count($shijiObj->city);
//echo$shengjiObj->city[$j]["cityname"]."";
//echo$shijiObjLen." ";
for($k=0;$k<$shijiObjLen;$k++){
//遍歷縣一級節點
$xianji_code=$shijiObj->city[$k]["url"];
echo'"'.$shijiObj->city[$k]["cityname"].'"=>';
echo$shijiObj->city[$k]["url"].", ";
//echo$xianji_code." ";
}
}
}
//print_r($chinaObj);
?>
通過XML介面根節點遞歸獲得全國幾千個縣以上城市cide code的代碼
9. PHP如何每天自動記錄當天的天氣
寫入資料庫進行記錄,欄位可以根據自己的需求設置
10. 誰有 15天天氣預報 源碼 最好是PHP的 或者API介面
你好可以使用中國天氣網的天氣插件 比較好用我就用這個