PHP天气API接口Word格式.docx

上传人:b****1 文档编号:15313591 上传时间:2022-10-29 格式:DOCX 页数:38 大小:22.78KB
下载 相关 举报
PHP天气API接口Word格式.docx_第1页
第1页 / 共38页
PHP天气API接口Word格式.docx_第2页
第2页 / 共38页
PHP天气API接口Word格式.docx_第3页
第3页 / 共38页
PHP天气API接口Word格式.docx_第4页
第4页 / 共38页
PHP天气API接口Word格式.docx_第5页
第5页 / 共38页
点击查看更多>>
下载资源
资源描述

PHP天气API接口Word格式.docx

《PHP天气API接口Word格式.docx》由会员分享,可在线阅读,更多相关《PHP天气API接口Word格式.docx(38页珍藏版)》请在冰豆网上搜索。

PHP天气API接口Word格式.docx

{

09.

static$realip;

10.

if(isset($_SERVER)){

11.

if(isset($_SERVER["

HTTP_X_FORWARDED_FOR"

])){

12.

$realip=$_SERVER["

];

13.

}elseif(isset($_SERVER["

HTTP_CLIENT_IP"

])){

14.

15.

}else{

16.

REMOTE_ADDR"

17.

}

18.

19.

if(getenv("

)){

20.

$realip=getenv("

21.

}elseif(getenv("

)){

22.

23.

24.

25.

26.

27.

28.

29.

return$realip;

30.

31.

32.

33.

34.

*获取IP地理位置

35.

*淘宝IP接口

36.

*@Return:

array

37.

38.

functiongetCity($ip)

39.

40.

$url="

41.

$ip=file_get_contents($url));

42.

if((string)$ip->

code=='

1'

){

43.

returnfalse;

44.

45.

$data=$ip->

data->

city;

46.

return$data;

47.

48.

49.

functiongetWeather($cityId)

50.

51.

52.

$weather=file_get_contents($url));

53.

return$weather;

54.

55.

function$web){

56.

$arr=array();

57.

foreach($webas$k=>

$w){

58.

if(is_object($w))$arr[$k]=$w);

//判断类型是不是object

59.

else$arr[$k]=$w;

60.

61.

return$arr;

62.

63.

$city=getCity(getIP());

64.

$city=str_split($city,strlen($city)-3);

65.

$city=$city[0];

66.

$cityUrl="

67.

$web=file_get_contents($cityUrl));

68.

$arr=$web);

69.

$weatherInfo=getWeather($arr[$city]);

70.

echo('

weather('

71.

echo($weatherInfo));

72.

echo("

)"

73.

74.

>

城市源码

!

DOCTYPEhtmlPUBLIC"

-//W3C//DTDXHTML1.0Transitional//EN"

"

http:

//www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"

htmlxmlns="

//www.w3.org/1999/xhtml"

head>

metahttp-equiv="

Content-Type"

content="

text/html;

charset=utf-8"

/>

title>

无标题文档<

/title>

linkrel="

stylesheet"

href="

main.css"

type="

text/css"

/head>

body>

divclass="

top"

top_content"

divid="

calendarArea"

<

spanclass="

datepic"

fontid="

weekday"

/font>

/span>

ul>

li>

spanid="

lunarday"

/li>

dateday"

/ul>

/div>

topWeatherArea"

ulclass="

cityWrap"

liclass="

name"

info"

weapic"

cityInfo"

scripttype="

text/javascript"

src="

../../js/jquery.js"

/script>

../../js/loadjs.js"

varweatherInfo;

varlunar;

vardate=newDate();

varg={"

晴"

:

"

00px"

"

多云"

0-40px"

暴雪"

0-480px"

大雪-暴雪"

暴雨"

0-360px"

大雨-暴雨"

暴雨-大暴雨"

大暴雨-特大暴雨"

大暴雪"

飑"

0-880px"

大雪"

0-440px"

中雪-大雪"

大雨"

0-320px"

中雨-大雨"

浮层"

0-920px"

雷阵雨"

0-160px"

雷阵雨并伴有冰雹"

0-200px"

霾"

轻雾"

0-840px"

雾"

冰雹"

0-680px"

沙尘暴"

0-760px"

强沙尘暴"

特大暴雪"

0-520px"

小雪"

0-600px"

小雨"

0-240px"

扬沙"

0-720px"

浮尘"

龙卷风"

0-800px"

弱高吹雪"

阴"

0-80px"

雨夹雪"

0-400px"

冻雨"

0-960px"

阵雪"

0-560px"

阵雨"

0-120px"

中雪"

0-640px"

小雪-中雪"

小雨-中雨"

0-280px"

中雨"

};

$(document).ready(function(){

$("

#weekday"

).html(date.getDate());

$.getScript("

getWeather.php"

lunar.php"

});

varweather=function(data){

weatherInfo=data;

.cityWrap.name"

).html(data.weatherinfo.city);

.cityInfo.name"

).html(data.weatherinfo.weather1);

.cityWrap.info"

).html(data.weatherinfo.city_en);

.cityInfo.info"

).html(data.weatherinfo.st1+"

℃"

.weapic"

).css("

background-position"

g[data.weatherinfo.weather1]).show();

varlunar=function(data){

lunar=data;

varmonth=data.month;

varday=data.day;

#lunarday"

).html("

农历"

+month+day);

#dateday"

).html(date.getFullYear()+"

."

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 求职职场 > 面试

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1