㈠ php 頁面調用天氣預報web服務 我想在一個PHP頁面直接調用現成的webservice
完全可以。前提是要打開soap擴展,調用方法如下:
<?php
$client = new SoapClient('http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl');
$parm=array('theCityCode'=>'三亞','theUserID'=>'');
$result=$client->getWeather($parm);
print_r($result);
?>
㈡ PHP調用2345天氣問題
$var是一個數組,weatherid是數組中的一個元素。在此之前,一般會先給$var中的每一個元素賦值,例如:$var['weatherid'] = 300,那麼整個URL其實就是:http://tianqi.2345.com/t/7day_tq_js/300.js
㈢ 網站如何嵌入天氣預報插件
網站嵌入天氣預報插件方法如下:
1.在網路首頁搜索「天氣定製模塊」,打開名字中帶有新浪網的網站;
5.在瀏覽器中打開上一步中保存的文件,就可以看到效果了。
㈣ 給個天氣預報插件地址啊,要無廣告的哦,廣告的看著煩
<?php
/**
* 採集天氣預報
* @example
* weather::$cache = root.'chache/'; //如果不改緩存目錄,可以不寫
* $array = weather::get();
* @author lrenwang
* @e-mail [email protected]
*
*/
class weather{
/**
* 域名
*
* @var string
*/
static public $domain='http://qq.ip138.com';
/**
* 城市的連接
* @example /省份/城市.htm
*
* @var string
*/
static public $url='/weather/hebei/qinhuang.htm';
/**
* 緩存目錄
*
* @var string
*/
static public $cache='cache/';
/**
* 更新頻率,小時為單位
*
* @var unknown_type
*/
static public $h=1;
/**
* 天氣預報對應的圖片路徑
*
* @var unknown_type
*/
static public $img = 'images/weather/';
/**
* 獲得今日,明日天氣預報
*
* @return array
*/
static function get()
{
$time=time();
//緩存文件位置
$cache_file = self::$cache.'weather.dat';
//判斷緩存文件是否存在,沒有則生成
if(!is_file($cache_file)){
if(!is_dir(self::$cache))
mkdir(self::$cache,0777,true);
self::get_($cache_file);
}
//判斷緩存是否過期,過期則重新生成
if($time-filemtime($cache_file)>=3600*3){
self::get_($cache_file);
}
$arr=unserialize(file_get_contents($cache_file));
return $arr;
}
/**
* 獲得緩存
*
* @param unknown_type $cache_file
*/
static public function get_($cache_file)
{
$con = file_get_contents(self::$domain.self::$url);
preg_match('~<table width="700" borderColorDark="#ffffff".*?>(.*?)</table>~s',$con,$table);
preg_match_all('~<tr.*?>(.*?)</tr>~s',$table[1],$trs);
$i=0;
$array = array();
foreach ($trs[1] as $tr)
{
++$i;
preg_match_all('~<t[dh].*?>(.*?)</t[dh]>~s',$tr,$tds);
$array[0][] = self::I($tds[1][1]);
$array[1][] = self::I($tds[1][2]);
}
$array[0][1] = self::get_img($array[0][1]);
$array[1][1] = self::get_img($array[1][1]);
file_put_contents($cache_file,serialize($array));
}
/**
* 數據輸出測試
*
* @param unknown_type $data
* @param unknown_type $s
*/
static public function P($data,$s=0)
{
echo "<pre>";
if (is_array($data))
var_export($data);
else
echo $data;
echo '</pre>';
if ($s==0)
exit();
}
/**
* 轉碼
*
* @param unknown_type $str
* @return unknown
*/
static public function I($str)
{
return iconv('GB2312','UTF-8',$str);
}
/**
* 獲得圖片的URL,此處可擴展,把圖片抓取到本地, 增加訪問速度
*
* @param string $str
* @return string
*/
static public function get_img($str)
{
preg_match('~src=["\']?(.*?)["\']? ~s',$str,$p);
return self::$img.pathinfo($p[1],PATHINFO_BASENAME);
}
}
//print_r();
$weather = weather::get();
echo "<img src={$weather[0][1]}>";
?>
㈤ 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的代碼
㈥ 怎麼利用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;
你可以隨便調試 記得獎勵哦
㈦ php在日歷上面顯示天氣預報這么顯示 我日歷代碼已經寫好在下面這么添加天氣預報
直接用中國天氣網的插件就可以
㈧ 網頁天氣預報插件代碼
不用安裝插件,你把下面的代碼插入你的網頁中就可以了:第一種: 代碼: <iframe width="145" height="130" border="0" align="center" marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling="no" src="" allowTransparency="true"></iframe> 效果預覽: 說明:這種適合於在網頁的邊欄插入。但一個缺點是,上面的4個城市是既定的,無法改成別的。插入時,選好網頁上的位置,直接將左欄的源代碼全部拷進去就行了 第二種: 代碼: <IFRAME ID='ifm2' WIDTH='189' HEIGHT='190' ALIGN='CENTER' MARGINWIDTH='0' MARGINHEIGHT='0' HSPACE='0' VSPACE='0' FRAMEBORDER='0' SCROLLING='NO' SRC=''></IFRAME> 效果預覽: 說明:這種 也適合於在網頁的邊欄插入。上面的城市可以自定,比如廈門可改成別的。定製的方法是修改我代碼中標紅的數字,從1開始代表「香港」開始,每個數字都代表一個城市,廈門是287,具體要哪個城市自己找一下罷。 第三種: 代碼: <IFRAME ID='ifm2' WIDTH='260' HEIGHT='70' ALIGN='CENTER' MARGINWIDTH='0' MARGINHEIGHT='0' HSPACE='0' VSPACE='0' FRAMEBORDER='0' SCROLLING='NO' src=""></iframe> 效果預覽: 說明:這種適合於在網頁的頭欄插入。上面的城市可以自定,比如 石家莊可改成別的。定製的方法是修改我代碼中標紅的數字。具體各個城市對照的id表可在此下載:城市名稱及ID對照表(請右鍵點擊—>另存為)。 第四種: 代碼: <iframe width="469" height="218" border="0" align="center" marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling="no" src="廈門" allowTransparency="true"></iframe> 效果預覽: 說明:這種適合於在網頁的正欄插入。上面的城市可以自定,比如廈門可改成別的。定製的方法是修改我代碼中標紅的 名稱。這里比較簡單,直接用漢字改就行了。比如是福州的,你就直接把「廈門」改成福州就行。 第五種: 代碼: <IFRAME ID='ifm1' WIDTH='405' HEIGHT='332' ALIGN='center' MARGINWIDTH='0' MARGINHEIGHT='0' HSPACE='0' VSPACE='0' FRAMEBORDER='0' SCROLLING='NO' SRC=""></IFRAME> 效果預覽: 第六種: 代碼: <iframe width=160 height=230 frameborder=0 scrolling=NO src=南昌></iframe> 效果預覽: 說明:這種適合於在網頁的邊欄插入。上面的城市可以自定,比如南昌可改成別的。定製的方法是修改我代碼中標紅的名稱。這里比較簡單,直接用漢字改就行了。比如是福州的,你就直接把「廈門」改成福州就行
很不錯哦,你可以試下
qgulqjbsvk62041435102011-10-12 9:09:45
㈨ 如何使用PHP調用API介面實現天氣查詢功能
最近在做微信公眾平台測試時,想在裡面子菜單上添加查詢未來幾天(包括今天)天氣的功能,就查找了下好用的天氣預報查詢介面API,使用比較多的有:國家氣象局天氣介面、新浪天氣預報介面、網路天氣預報介面、google天氣介面、Yahoo天氣介面等等,我使用的是網路提供的免費天氣查詢介面API,下面與大家分享下...
1、查詢方式:
網路提供的是根據緯度和城市名查詢天氣情況
2、介面事例: